Skip to main content


Project description


mocks api function returning fake data with specified shape. Every url can have different shape, these are represented in skema format in a yaml file,

/posts/: |
        ok: Bool
        data: [
            postName: Str
            date: Str
            id: Int
/post/: |
        ok: Bool
                name: Str
                id: Int
            description: Str

The shape of the data can change based on url hostname or path. an example:

from mock_api import mock_function
from myapi import api_call

with mock_function('myapi.api_call', 'api_shape.yml', arg=0):
    data = api_call('/posts/')
    print(data) # {'ok': True, 'data': {'postName': 'sdfsdgx', 'date': 'sdfg4'}}

genrating the api shapes

You can generating the shapes calling many times the api

from mock_api import track_function
from myapi import api_call

with track_function('myapi.api_call', 'api_shape.yaml', ):

# a file api_shape.yaml is created
assert os.path.exists('api_shape)


  • change shape based on POST, GET ...
  • change shape based on parameters
  • add url parameters, like posts/:id/
  • remove Response root key maybe (but i can't use root arrays, Root: [...])
  • add possible codes, like 200, 400, then change shape based on them

Project details

Download files

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

Source Distribution

mock_api-0.0.7.tar.gz (4.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page