prodapi
A thin layer on top of FastAPI with the following features:
- Integrates with FastAPI-Security to add a custom route
/users/me(path is overridable) - Easily add CORS to your app by calling
app.with_basic_cors() - Add health routes to the app via
app.with_health_routes(). Adds a liveness route at/__is-aliveand a readiness route at/__is-ready(both paths can be overridden). Useful together with Kubernetes liveness and readiness probes for example. - And, thanks to FastAPI, all routes are automatically added to the API documentation
Installation
pip install prodapi
Example
from prodapi import ProdAPI, ApiRouter, FastAPISecurity
# First let's set up security, via FastAPI-Security
security = FastAPISecurity()
# Set up HTTP Basic Auth
security.init_basic_auth([
{"username": "johndoe", "password": "123"},
{"username": "janedoe", "password": "abc123"},
])
# Set up OAuth2 and OIDC
# NOTE: There is also `init_oauth2_through_jwks` in case OIDC is not available
security.init_oauth2_through_oidc(
"https://my-auth0-tenant.eu.auth0.com/.well-known/openid-configuration",
)
# Make sure that basic auth user `jane` and OAuth2 user
# `p56OnzZb8KrWC9paxCyv8ylyB2flTIky@clients` gets all permissions automatically.
# NOTE: For basic auth you have to set up permissions this way, for OAuth2 permissions
# will be automatically extracted from the incoming JWT token (via the key
# `permissions`, which might only be implemented for Auth0)
security.add_permission_overrides({
"jane": ["*"],
"p56OnzZb8KrWC9paxCyv8ylyB2flTIky@clients": ["*"],
)
# Now we're ready to create the app
# NOTE: ProdAPI is just a thin layer on top of `fastapi.FastAPI`
app = ProdAPI()
# CORS - Allow any origins, methods and headers. Don't expose any headers.
app.with_basic_cors()
# Add routes `/__is-alive` and `/__is-ready`. Useful together with Kubernetes or similar
# URL paths are configurable.
app.with_health_routes()
# Enable `/users/me` route to get info about the user. URL path is configurable.
app.with_user_routes(security)
# Create our app specific API router and our routes
products_router = ApiRouter()
@products_router.get("/products")
def list_products():
return []
app.include_router(products_router)
# And we're done! Now just use uvicorn or similar to deploy.
TODO
- Create cli utility (using tiangolo typer?), which can generate:
- A stub project using
prodapi - Frontend (React?)
- docker-compose.yml and Dockerfile
- Kubernetes deployment files
- A stub project using
Metadata
Release files for prodapi 0.1.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 | Provenance | Actions |
|---|---|---|---|---|
| prodapi-0.1.0.tar.gz | 7.6 kB | Without provenance | Details for prodapi-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| prodapi-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for prodapi-0.1.0-py3-none-any.whl |
Total release size: 15.3 kB
Release files / prodapi-0.1.0.tar.gz
| Download URL | prodapi-0.1.0.tar.gz |
|---|---|
| Size | 7.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dbc41011f82a661b8096496e7fda25c6e089a8e653e09024c0d3ad9d9416c633
|
|
BLAKE2b-256 checksum How to use checksums |
ef19baa8abda086fc8dd6863f8373ee186d373543f839e10d8b5641c5a3cd724
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.5 CPython/3.9.2 Linux/5.4.0-1041-azure
|
Release files / prodapi-0.1.0-py3-none-any.whl
| Download URL | prodapi-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ed2c60611d36fdbc05f12c39563a7e66e848c58a16b4d834ca8c916c8766f172
|
|
BLAKE2b-256 checksum How to use checksums |
e563e8d70a35a462b17118ef380f0bcd0745620afac655adecc2261e0d98c2b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.5 CPython/3.9.2 Linux/5.4.0-1041-azure
|
Security for prodapi 0.1.0
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.