This release is a pre-release and may not be stable for production use.
asgi-replay
A tool for recording and replaying requests using ASGI.
Very early prototype
This is an early prototype. I have used this tool exactly once.
Installation
pip install asgi-replay
Usage
The tool provides two commands - one for recording logs of ASGI requests and one for running a server to replay them.
Recording
asgi-replay record https://www.example.com log.json --port 8000
This runs a local server on port 8000 that proxies content through to www.example.com - and logs each request to log.json.
The log.json file will be over-written for each request. This tool is mainly designed for capturing a single HTTP interaction.
If you add --increment a new file will be written for each request, starting with log-0.json and then log-1.json and so on.
Replaying
To replay a single log - such that any HTTP request to the local server will replay that exact response - run this:
asgi-replay replay log.json --port 8000
(8000 is the default port for both commands.)
What I built this for
I wanted to build a tiny application that could simulate the streaming response from an OpenAI completion endpoint.
The app I built is here: https://github.com/simonw/openai-canned-completion
You can hit it using LLM like this:
OPENAI_API_KEY='x' \
OPENAI_API_BASE='https://openai-canned-completion.vercel.app/v1' \
llm 'hello'
I first ran the following on my own machine:
asgi-replay record https://api.openai.com log.json --port 8000
Then:
OPENAI_API_BASE='http://localhost:8000/v1' \
llm 'hello'
This ran a real request against OpenAI and saved the response in log.json.
Then I ran the replay like this:
asgi-replay record https://api.openai.com log.json --port 8000
And when I ran the llm command again I got the same response, without hitting the OpenAI API:
OPENAI_API_BASE='http://localhost:8000/v1' \
llm 'hello'
Hello! How can I assist you today?
I copied the saved ASGI logs into this ASGI app: https://github.com/simonw/openai-canned-completion/blob/main/canned.py
Metadata
Release files for asgi-replay 0.1a0
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 |
|---|---|---|---|---|
| asgi-replay-0.1a0.tar.gz | 3.2 kB | Without provenance | Details for asgi-replay-0.1a0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| asgi_replay-0.1a0-py3-none-any.whl | Python 3 | none | any | Details for asgi_replay-0.1a0-py3-none-any.whl |
Total release size: 6.6 kB
Release files / asgi-replay-0.1a0.tar.gz
| Download URL | asgi-replay-0.1a0.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3721a22aa3a0c207cc2d70c9f9865c91e786686d6475e958a13dd61b6acb910f
|
|
BLAKE2b-256 checksum How to use checksums |
e5e891358cb41bc2eb1861927fa8376bc622c3d3bfc402081a5f180969ff7ebf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / asgi_replay-0.1a0-py3-none-any.whl
| Download URL | asgi_replay-0.1a0-py3-none-any.whl |
|---|---|
| Size | 3.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fe48bac162e73a96d1e9232287aa5a3bbed55f73cda9af121e922aad7c6a4c37
|
|
BLAKE2b-256 checksum How to use checksums |
f0e41c8fe2155bb9317e0702fdd4e3655083908cd637652efdaa38e3224be819
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Security for asgi-replay 0.1a0
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.