Skip to main content

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

Project description

Placebo build

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.

Project details

Download files

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

Files for python-placebo, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size python-placebo-1.0.0.tar.gz (8.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page