coopapi
package for setting up a quick API built on the FastAPI framework
example
Setup a dummy pydantic dataclass that has some attributes
from pydantic.dataclasses import dataclass as pydandataclass, Field
from cooptools.randoms import a_string, a_phrase
class DummySchemaConfig:
allow_population_by_field_name = True
schema_extra = {
"example": {
'id': a_string(10),
'desc': a_phrase(10),
'active': True,
}
}
@pydandataclass(config=DummySchemaConfig)
class DummySchema:
id: str = Field(...)
desc: str = Field(...)
active: bool = Field(...)
Using the dummySchema pydantic dataclass, stubb in some callbacks and create the api shell object. This will be used to setup the core funcationality of our API. Create a FastAPI() object that is used to host our router.
Note: multiple routers (shells) can be added to the same FastAPI() object such that you can build out an extensive API.
Finally, serve the app...
from examples.dummySchema import DummySchema
from coopapi import createRequestCallback, ApiShell, deleteRequestCallback
import uvicorn
from fastapi import FastAPI
# create the callbacks for what should be done when the various endpoints are called. This is likely a
# db interaction or a forwarding request.
create_callback: createRequestCallback = lambda r, t: t
delete_callback: deleteRequestCallback = lambda r, t: True
# setup the api itself, use a base FastAPI object and then an api_shell which has its router included in the
# base api
app = FastAPI()
api_shell = ApiShell(target_schema=DummySchema,
base_route='/dummy',
on_create_callback=create_callback,
on_delete_callback=delete_callback)
app.include_router(api_shell.router, tags=["dummy_shell"])
# serve the app
uvicorn.run(app, port=1219)
You can visit the docs site of the created api at http://localhost:1219/docs#/
Metadata
Release files for coopapi 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 | Actions |
|---|---|---|---|---|
| coopapi-1.1.tar.gz | 8.8 kB | Without provenance | Details for coopapi-1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| coopapi-1.1-py3-none-any.whl | Python 3 | none | any | Details for coopapi-1.1-py3-none-any.whl |
Total release size: 17.6 kB
Release files / coopapi-1.1.tar.gz
| Download URL | coopapi-1.1.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7add9ad6f180f70d2e27f9a3162cf19e5bd64f6c9759fa5ae5b617e644d9650f
|
|
BLAKE2b-256 checksum How to use checksums |
bc6a150e287fd50f7e83ba075ab20a581ba232a8c318b1c1e8989d28307f5afa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
|
Release files / coopapi-1.1-py3-none-any.whl
| Download URL | coopapi-1.1-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ff8c49f05b507c60ed3c7993d7cfc753d38f58c4d8ce2bce5b97295187478e86
|
|
BLAKE2b-256 checksum How to use checksums |
634b62cad00a51e17f062d2cad0098250182b98062e15fe3266bc5b593500357
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
|
Security for coopapi 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.
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.