Skip to main content
PyMocky

Python package codecov

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&param2=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

Buy Me a Coffee at ko-fi.com

License

MIT

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)

Source distribution for pymocky 1.3.0
File Size Uploaded
pymocky-1.3.0.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pymocky 1.3.0
File Interpreter ABI Platform
pymocky-1.3.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page