Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
A Python tool to mock API easily and humanly without any coding.
Overview | Python versions support | Quickly Start | Documentation
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.
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.
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.
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
orfastapi
. It means that PyMock-API only supports 2 Python web frameworks: Flask and FastAPI.
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.'
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."%
Currently, it won't have documentation. But it would have soon.
PyMock-API follows coding styles black and PyLint to control code quality.
PyMock-API still a young open source which keep growing. Here's its download state:
FAQs
🕸🤖👺 A Python tool to mock API easily and humanly without any coding.
We found that PyMock-API demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.