Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (
Help us improve Python packaging - Donate today!

Placebo is a tool for mocking external API's in python applications.

Project Description


Placebo is a utility that help implenting mock api responses in a reusable and composable way.


Sample mock:

class UsersResponse(BaseMock):
    url = ''
    body = json.dumps([{'name': 'Huseyin',
                        'last_name': 'Yilmaz'}])

And usage of the mock will be like this:

def users_api_test(self):

You can decorate any function or method with this decorator. Even django views:

def users_list_view(request):


When a decorator is applied, I will be using httppretty or httmock libraries to mock given endpoint from the socket or requests library layer. So I am thinking about creating a backend structure that can be attach to the library. So I will be able switch between different mocking library backends.

Bad side of this is I will need to create a generic structure and convert specific backend requests to generic PlaceboRequest backend.


I am thinking about creating 2 backends for now httpretty and httmock. In my expericence, httmock is a lot better choice for some usecases because httpretty cannot be applied on runtime. It must be applied on initialization. (This is not an issue for 90% of use cases.).


To test request data, I will need to catch requests and provide some kind interface so request can be inspected on tests. interface for this can be a function on main module like placebo.get_last_reqest()

Debug mode:

This abstraction is good. But when urls needs to be updated it becomes really hard to debug those kind of interfaces. So there should be a debug mod that prints out all decision to console.

Regexp URL’s

There should be a way to define urls with some kind of regexp. For some cases, we might want to be able to mock whole sub directories.

Release History

This version
History Node


History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Hash SHA256 Hash Help Version File Type Upload Date
(8.4 kB) Copy SHA256 Hash SHA256
Source Aug 13, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting