Deploy a mock server for use in testing.
Project description
chora
Warning: chora is intended for development and testing only. Do not use this server in production environments. If you do use this in production, and get your ass handed to you, please don't come crying to me.
chora is a mock HTTP server for Python that serves responses based on your file system structure. It's designed for testing and development, allowing you to quickly simulate APIs or static content by simply organizing files and directories.
Features
- File-based routing: Map HTTP endpoints to files and folders.
- Supports multiple HTTP methods: Serve different responses for GET, POST, etc., using file naming conventions.
- Easy to configure: No code changes needed—just update the file system.
- Great for testing: Quickly mock APIs for frontend or integration tests.
How It Works
- Each directory represents a route.
- Files inside directories represent responses, statuses, and headers for specific HTTP methods and endpoints.
- Dynamic request handling is done with a special HANDLE script.
- The server reads the file system to determine how to respond to incoming requests.
Example Structure
example/
├── users/
│ └── GET/
│ │ ├── HEADERS # Custom headers for GET /users
│ │ ├── DATA # Response body for GET /users
│ │ └── STATUS # HTTP status code for GET /users
│ └── POST/
│ │ ├── HEADERS # Custom headers for POST /users/
│ │ ├── DATA # Response body for POST /users/
│ │ └── STATUS # HTTP status code for POST /users/
│ └── PUT/
│ └── HANDLE # Custom handler for PUT /users/
└── status/
└── POST/
├── HEADERS # Custom headers for POST /status
├── DATA # Response body for POST /status
└── STATUS # HTTP status code for POST /status
A request to GET /users will return the contents of users/GET/DATA, with headers from users/GET/HEADERS and status from users/GET/STATUS.
A request to PUT /users will execute the HANDLE script, with $1 containing the folder with the details of the request. The script is expected to introspect that and supply a path to a folder containing the DATA, HEADERS and STATUS files.
Installation
pip install chora
Usage
chora --root ./example --port 8080
- --root: Path to the directory containing your mock API structure.
- --port: Port to run the server on (default: 8000).
Customization
- Add new endpoints by creating directories and files.
- Use subdirectories for nested routes.
License
MIT
Author
pbhandari (pbhandari@pbhandari.ca)
For more information, see the project homepage: https://github.com/pbhandari/chora
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chora-0.3.0.tar.gz.
File metadata
- Download URL: chora-0.3.0.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0d8b58c0c2e94d938ecdc35f230236d360bae032e6fe833d84ebfda853a1e8b
|
|
| MD5 |
1a2138a64656eca58f8cc2780de110df
|
|
| BLAKE2b-256 |
c0abb29ad355f4f026486a2813e50a1adf893baada2bdd48142d98872c40c4bb
|
File details
Details for the file chora-0.3.0-py3-none-any.whl.
File metadata
- Download URL: chora-0.3.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d762d6049c63216307ae5badd3f0cb2f9a75aba76ae25b9efb558fdde1f227d2
|
|
| MD5 |
2252e2896a1ad869594a6b2c7c4c9fd4
|
|
| BLAKE2b-256 |
d1fcf01c042a26a97f9eb04dbf976bf0f1e77b366e629a668b43e393aa370af7
|