custom_openai
custom_openai is a drop-in replacement for the official OpenAI Python SDK, enabling you to easily customize, standardize, and enrich the API responses for your own post-processing, logging, RAG pipelines, or monitoring needs.
It supports both synchronous and asynchronous usage, with robust support for streaming and complete compatibility with the OpenAI API.
🚀 Features
- Plug-and-play: Fully compatible with the OpenAI client interface. Just swap your import and go.
- Custom response fields: Every
.create()call (sync/async/streaming) includes a.flashqueryattribute for easy extraction of processed or enriched response data. - Streaming support: Automatically injects your custom data into the final item in async generator streams.
- No monkey-patching: Cleanly extends OpenAI’s classes without risky global side effects.
📦 Installation
pip install flashquery
🔥 Quickstart
Synchronous Example
from flashquery.client import CustomLangchainClient
client = CustomLangchainClient(
provider="openai",
model="gpt-4o-mini",
temperature=0,
api_key="sk-..."
)
response = client.generate([{"role": "user", "content": "Say hello?"}])
print(response.flashquery) # Your custom field!
Streaming Example
import asyncio
from flashquery.client import CustomLangchainClient
async def main():
client = CustomLangchainClient(
provider="openai",
model="gpt-4o-mini",
temperature=0,
api_key="sk-..."
)
response = client.astream([{"role": "user", "content": "Oi, tudo bem?"}])
async for chunk in response:
print("Chunk:", chunk.flashquery)
asyncio.run(main())
⚙️ How it Works
- CustomOpenAIClient and CustomAsyncOpenAIClient inherit from the official OpenAI clients, overriding
.create()methods ofresponsesandchat.completions. - After each response is created, a new
.flashqueryattribute is attached. - In streaming mode,
.flashqueryis set on the last chunk yielded from the generator.
🤝 Contributing
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
📄 License
MIT License
Need help? Open an issue or contribute on GitHub!
Metadata
Release files for flashquery 0.8.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 | |
|---|---|---|---|
| flashquery-0.8.0.tar.gz | 4.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flashquery-0.8.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.7 kB
Release files / flashquery-0.8.0.tar.gz
| Download URL | flashquery-0.8.0.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
81427a5dd8b294264b37ce10e34b14b085d4b107589cf66eff9c106e2ae1e372
|
|
BLAKE2b-256 checksum How to use checksums |
5f47e4d0df8427c03a4c9bafa391d4b7296ef4dfbf1abd37e9e22cc6e9df5550
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / flashquery-0.8.0-py3-none-any.whl
| Download URL | flashquery-0.8.0-py3-none-any.whl |
|---|---|
| Size | 4.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8bd2c222849d37c4d655ccd093704ba6a64183cee5e07bf2cb55d1617e2094f0
|
|
BLAKE2b-256 checksum How to use checksums |
87f403458300c1febfbb5bda05d6f94b22f30f4c3e32f49c3e6ffcca5892d275
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|