pyzeus ⚡
The cors middleware that enables a FastAPI server to handle cors requests. It also handles preflight requests 😃.
Installation
pip install pyzeus
or
pip3 install pyzeus
Default Response Headers
If no options are provided, the response headers will be as follows:
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,HEAD,PUT,PATCH,POST,DELETE
Access-Control-Allow-Headers: Content-Type,Origin
Access-Control-Max-Age: 5
NOTES
- The allow_headers will always append
Content-TypeandOriginto your response headers so no need to add it to the list - To handle preflight requests you will specifically need to add a
@router.options(...)to your router
Usage Examples
Router Instance
This implementation is equally
from pyzeus import zeus
from fastapi import APIRouter, Depends
router = APIRouter(dependencies=[Depends(zeus().thunder)])
@router.get("/")
async def hander():
return { "message": "lorem ipsum" }
@router.options("/")
async def options_hander():
return None
Specific Route
This implements a sync or async agnostic decorator that requires you to add request and response parameters in your route handler. Worry not, it works if you have pydanyic classes too! Needs python 3.8+ or run pip install typing_extensions
from pyzeus import zeus
from fastapi import APIRouter, Depends
router = APIRouter()
# Synchronous example
@router.get("/")
@zeus().smite
def synchronous_handler(request: Request, response: Response):
return { "message": "lorem ipsum" }
# Asynchronous example
@router.get("/")
@zeus().smite
async def asynchronous_handler(request: Request, response: Response):
return { "message": "lorem ipsum" }
# Pydantic example
class Item(BaseModel):
name: str
@router.post("/")
@zeus().smite
async def asynchronous_handler(request: Request, response: Response, item: Item):
return { "message": item }
Changelog
v0.1.x
v0.1.3
- Fixed Origin determination for not preflight requests
v0.1.2
- Removed
functools, andtyping_extensionsfrom dependencies
v0.1.1
- Added changelog to README
- Added dependencies
v0.1.0
- Initial release
Metadata
Release files for pyzeus 0.1.3
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 |
|---|---|---|---|---|
| pyzeus-0.1.3.tar.gz | 5.4 kB | Without provenance | Details for pyzeus-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyzeus-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for pyzeus-0.1.3-py3-none-any.whl |
Total release size: 11.1 kB
Release files / pyzeus-0.1.3.tar.gz
| Download URL | pyzeus-0.1.3.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2eab4f6e0c553acfb4e5b158a14453a17899bff576dd989d844413dadcf2e81e
|
|
BLAKE2b-256 checksum How to use checksums |
7b6903c0ecaac3e306045c088bab90e37b54d3d8c06fced58a4dcea2041099e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / pyzeus-0.1.3-py3-none-any.whl
| Download URL | pyzeus-0.1.3-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f8f280a32ba52377fbca30eea4db3c9c862ce76b2417a04380638b38475e78c1
|
|
BLAKE2b-256 checksum How to use checksums |
db9ec22a72ec7acd4dc5c88d9479263e5f4309f4f76254991d2b8e3049d39027
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Security for pyzeus 0.1.3
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.