dev-server
Table of Contents
Installation
pip install dev-server
Usage
dev-server is a lightweight development HTTP server with three modes of operation:
Quick Start
dev-server <command> [options]
Commands
1. Mock Server
Start a mock HTTP server that returns predefined responses and stores request history.
dev-server [-p PORT] [--host HOST] mock [--responses FILE]
Features:
- Return predefined responses based on HTTP method and path
- Store all requests in memory for later retrieval
- Built-in endpoints:
GET /_ping- Health check endpoint (returns "pong")GET /_requests- Retrieve stored requests?last=true- Get only the last request?clear=true- Get all requests and clear the history
Response Mapping Format:
Create a JSON file with response mappings:
{
"GET:/api/users": {
"status_code": 200,
"headers": {
"Content-Type": "application/json"
},
"body": "[{\"id\": 1, \"name\": \"李明\"}, {\"id\": 2, \"name\": \"García\"}]"
},
"POST:/api/users": {
"status_code": 201,
"body": "{\"id\": 3, \"created\": true}"
}
}
2. Proxy Server
Start a proxy server that forwards requests to a target URL and records all traffic.
dev-server proxy <TARGET_URL> [-o OUTPUT] [--indent INDENT]
Features:
- Forward all requests to a target server
- Record requests and responses to a file (JSONL format)
- Useful for debugging, testing, and traffic analysis
Example:
# Proxy to example.com and save to file
dev-server proxy https://api.example.com -o requests.jsonl
# Proxy with formatted JSON output
dev-server proxy https://api.example.com -o requests.jsonl --indent 2
# Proxy to stdout (default)
dev-server proxy https://api.example.com
3. Single Request Server
Serve a single HTTP request, print the request details, and optionally open a URL in the browser.
dev-server [-p PORT] [--host HOST] single-request [URL]
Features:
- Ideal for OAuth callbacks and webhook testing
- Automatically opens URL in browser (if provided)
- Returns full request details as JSON
- Server terminates after handling one request
Example:
# Capture a single request
dev-server single-request
# Open OAuth URL and capture callback
dev-server single-request "https://oauth.example.com/authorize?client_id=xyz"
Global Options
Note: Global options must be placed BEFORE the command name.
-p, --port PORT- Port to run the server on (default: 3000)--host HOST- Host to bind the server to (default: 127.0.0.1)-t, --timeout TIMEOUT- Timeout for the server in seconds-v, --verbose- Increase verbosity level (can be used multiple times)
Examples
# Mock server on custom port with verbose logging
dev-server -p 8080 -vvv mock --responses api-mocks.json
# Proxy server with request recording on custom port
dev-server -p 8000 proxy https://jsonplaceholder.typicode.com -o captured.jsonl
# Single request for OAuth callback on custom port
dev-server -p 3000 single-request "https://oauth.example.com/authorize?client_id=xyz"
# Mock server with custom host and timeout
dev-server --host 0.0.0.0 -t 60 -p 8080 mock --responses api-mocks.json
# Check stored requests in mock server
curl http://localhost:3000/_requests
# Get last request only
curl http://localhost:3000/_requests?last=true
# Get all requests and clear history
curl http://localhost:3000/_requests?clear=true
Programmatic Usage
SimpleServer
The SimpleServer class provides a simple WSGI server interface that can be used to build custom HTTP tooling. It abstracts away WSGI complexities and provides a clean request/response API.
Basic Example
from dev_server.simple_server import SimpleServer, SimpleRequestEvent, SimpleResponseEvent
def my_handler(request: SimpleRequestEvent) -> SimpleResponseEvent:
"""Handle incoming HTTP requests."""
return {
"status_code": 200,
"headers": {"Content-Type": "text/plain"},
"body": [b"Hello, World!"],
}
server = SimpleServer(request_handler=my_handler)
server.serve_forever(host="127.0.0.1", port=8080)
Request Event Structure
The SimpleRequestEvent provides parsed request data:
{
"method": "GET", # HTTP method (GET, POST, PUT, DELETE, etc.)
"url": "/api/users", # Request path
"headers": { # Request headers (dict)
"Content-Type": "application/json",
"User-Agent": "..."
},
"params": { # Query parameters (dict[str, list[str]])
"page": ["1"],
"limit": ["10"]
},
"content": b"..." # Request body as bytes
}
Response Event Structure
Return a SimpleResponseEvent from your handler:
{
"status_code": 200, # HTTP status code
"headers": { # Response headers (dict)
"Content-Type": "application/json"
},
"body": [b"..."] # Response body as iterable of bytes
}
License
dev-server is distributed under the terms of the MIT license.
Metadata
Release files for dev-server 0.1.1
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 | |
|---|---|---|---|---|
| dev_server-0.1.1.tar.gz | 15.0 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dev_server-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.4 kB
Release files / dev_server-0.1.1.tar.gz
| Download URL | dev_server-0.1.1.tar.gz |
|---|---|
| Size | 15.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
01dcac64760c19dc3a41e4dbdaa8d0b302be321372deec9e77d7fb92c2b27cbb
|
|
BLAKE2b-256 checksum How to use checksums |
def2ee67458685cac2191cdfb0b96c34e502036dc6a6a4324a7f35b2b487bc92
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2025.
Transparency logRelease files / dev_server-0.1.1-py3-none-any.whl
| Download URL | dev_server-0.1.1-py3-none-any.whl |
|---|---|
| Size | 13.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e8dd68c7e35b3e411b9be352d3f48f021615b49d49af4ee3b54b657fd4b01a37
|
|
BLAKE2b-256 checksum How to use checksums |
12251d2c717376db08effee0844a5c0664ceacf1905f7a2a43f658a9325e875c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2025.
Transparency logSecurity for dev-server 0.1.1
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for dev_server-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2025.
Transparency logA 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.