Skip to main content

🕸🤖👺 A Python tool to mock API easily and humanly without any coding.

Project description

PyMock-API

PyPI Release CI codecov pre-commit.ci status Quality Gate Status documentation License: MIT

A Python tool to mock API easily and humanly without any coding.

Overview | Python versions support | Quickly Start | Documentation


Overview

Do you ever have experience about needing to set up a very simple application and write some APIs with hardcode response again and again for developing Font-End site? PyMock-API provides a command line tool to let developers could quickly and easily set up application to mock APIs with configuration only.

Python versions support

The code base of PyMock-API to set up an application still depends on third party Python package, i.e., Flask, FastAPI, etc. So the Python versions it supports also be affected by them, e.g., Flask only supports Python version 3.8 up currently. So PyMock-API also only supports version Python 3.8 up.

Supported Versions

Quickly Start

Here section would lead you quickly start to set up your first one application by PyMock-API for mocking APIs easily.

In basically, it has 3 steps: install the package, configure settings about the APIs for mocking and run command.

Install command line tool

First of all, we need to install the command line tool and the way to install is same as installing Python package by pip.

>>> pip install pymock-api

If the runtime environment has installed some Python web framework, e.g., Flask, you also could install Pymock-API with one specific option as following:

>>> pip install "pymock-api[flask]"

Then it would only install the lowest Python dependencies you need.

After you done above step, please make sure the command line tool feature should work finely by below command:

>>> mock-api --help

Note

Please take a look at option --app-type (this option is in subcommand mock-api run) of the command line tool. Its option value could be auto, flask or fastapi. It means that PyMock-API only supports 2 Python web frameworks: Flask and FastAPI.

Configure setting to mock target APIs

Now, we have the command line tool. Let's configure the settings it needs to set up application to mock API.

The configuration format of PyMock-API to use is YAML. So let's write below settings in YAML file:

mocked_apis:
  google_home:
    url: '/google'
    http:
      request:
        method: 'GET'
      response:
        strategy: string
        value: 'This is Google home API.'

Run command to set up application

Now, both of the command line tool and configuration have been already. So let's try to run the command to set up application!

>>> mock-api run -c <your configuration path>

You would see some log messages in terminal and that is the log of web server by one specific Python web framework.

And you could test the API by curl:

>>> curl http://127.0.0.1:9672/google
"This is Google home API."%

demonstration

Documentation

Currently, it won't have documentation. But it would have soon.

Coding style and following rules

PyMock-API follows coding styles black and PyLint to control code quality.

Code style: black linting: pylint

Downloading state

PyMock-API still a young open source which keep growing. Here's its download state:

Downloads Downloads

License

MIT License

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

pymock_api-0.2.0.tar.gz (63.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymock_api-0.2.0-py3-none-any.whl (88.5 kB view details)

Uploaded Python 3

File details

Details for the file pymock_api-0.2.0.tar.gz.

File metadata

  • Download URL: pymock_api-0.2.0.tar.gz
  • Upload date:
  • Size: 63.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.10.15 Linux/6.5.0-1025-azure

File hashes

Hashes for pymock_api-0.2.0.tar.gz
Algorithm Hash digest
SHA256 35faabd27250736f57e9d294c88e07086edab5b19075d2f95e6f553f89bc964a
MD5 3e11d841ca8fcbcfd8304e7e860602bf
BLAKE2b-256 f46e9b88b30380e5a707946484e881bd6daa319318781e3d5558a3c5e852aced

See more details on using hashes here.

File details

Details for the file pymock_api-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pymock_api-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 88.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.10.15 Linux/6.5.0-1025-azure

File hashes

Hashes for pymock_api-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f548190097c6e69dcb632813300089a1c17b9804c01aecd013f5123b47b5279d
MD5 1e86f35a08ccbba34044a91c7fce55b6
BLAKE2b-256 5023c819d9c2a9eec206d1daf2bf5b112a62934e3d56f52a519f10ef1a1d5cee

See more details on using hashes here.

Supported by

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