Mock server to return static response.
Install
python3 -m pip install pymocky
Check with command:
pymocky -h
How to use
pymocky -p extras/sample/
Test with command (need curl):
curl http://localhost:9000/login
To change from default scenario to other use (server need be running):
pymocky --update-scenario "login-error"
Test again with command (need curl):
curl http://localhost:9000/login
Example of YAML file
mappings:
- id: hello_world
scenario: login-success
request:
url: .*pymocky_hello_world.*
method: post
query_string: .*param1=value¶m2=value2
form_fields:
username: .*demo
password: .*12345
headers:
"Content-Type": "application/json"
body: .*Hello World.*
response:
headers:
"Content-Type": "application/json"
body_raw: Hello world from pymocky!
body_file: files/dummy.xml
body_json:
success: false
data:
errors: []
body_image: images/image1.png
body_python: files/dummy.py
sys_path: ["auto"]
You can use “body_raw”, “body_file”, “body_json”, “body_image” or “body_python” as response type.
When you use “body_python” you can add array “sys_path” and pymocky will add these paths to “sys.path” list. The list of “sys.path” is reloaded to original (when pymocky start is stored a copy of this list) everytime that YAML files are parsed again. When you use “auto” in the array, the path will be the directory of python file to be execute.
body_raw: Raw text as response
body_file: File content with mimetype discovery by extension
body_json: Json as YAML object or string
body_image: Image file with mimetype discovery by extension
body_python: Python file to be executed
Change scenario
To change from default scenario to other use (server need be running):
pymocky --update-scenario "login-error"
Testing
You need install test dependencies with the command:
python3 -m pip install -r requirements_tests.txt
To execute all tests use the command:
python3 -m pytest tests
To coverage test use the command:
python3 -m pytest --cov=. --cov-report=xml --cov-report=html tests
To install locally during development:
python3 setup.py install
or:
python3 -m pip install -e .
Packaging
To package and upload for distribution on PyPi server use:
python3 setup.py upload
Contributing
Fork the project and clone locally.
Create a new branch for what you’re going to work on.
Push to your origin repository.
Create a new pull request in GitHub.
Buy me a coffee
License
Copyright (c) 2020-2026, Paulo Coutinho
Metadata
Release files for pymocky 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pymocky-1.3.0.tar.gz | 4.9 kB | Without provenance | Details for pymocky-1.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pymocky-1.3.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for pymocky-1.3.0-py2.py3-none-any.whl |
Total release size: 9.4 kB
Release files / pymocky-1.3.0.tar.gz
| Download URL | pymocky-1.3.0.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
031412539d315df1b472e3c08cebf0ba683f73cdd25523235ff564b857e3fed4
|
|
BLAKE2b-256 checksum How to use checksums |
7f816a1973d0d846e3e8308bc1e16c86349b4b94af7c2ec7b455ec0612a240b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Release files / pymocky-1.3.0-py2.py3-none-any.whl
| Download URL | pymocky-1.3.0-py2.py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
b49827facbca14bdefc8790cdc9021a15274b92925238c9fca77a13fde6fe371
|
|
BLAKE2b-256 checksum How to use checksums |
805fda57ba7cd62a6c8cf1d33f41d3d73058b487ecc61384d82f0d06c25ddd5a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Security for pymocky 1.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.