coopapi-0.6
توضیحات
Tools for setting up an API. Built on the FastAPI framework
| ویژگی | مقدار |
|---|---|
| سیستم عامل | - |
| نام فایل | coopapi-0.6 |
| نام | coopapi |
| نسخه کتابخانه | 0.6 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | tburns |
| ایمیل نویسنده | tyler.tj.burns@gmail.com |
| آدرس صفحه اصلی | https://github.com/tylertjburns/coopapi |
| آدرس اینترنتی | https://pypi.org/project/coopapi/ |
| مجوز | MIT |
# coopapi
package for setting up a quick API built on the FastAPI framework
# example
Setup a dummy pydantic dataclass that has some attributes
```buildoutcfg
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...
```buildoutcfg
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#/

نیازمندی
| مقدار | نام |
|---|---|
| ==3.6.2 | anyio |
| ==2022.12.7 | certifi |
| ==3.0.1 | charset-normalizer |
| ==8.1.3 | click |
| ==0.4.6 | colorama |
| ==1.2 | cooptools |
| ==0.89.0 | fastapi |
| ==0.14.0 | h11 |
| ==3.4 | idna |
| ==1.24.1 | numpy |
| ==1.10.4 | pydantic |
| ==2.28.2 | requests |
| ==1.3.0 | sniffio |
| ==0.22.0 | starlette |
| ==4.4.0 | typing-extensions |
| ==1.26.14 | urllib3 |
| ==0.20.0 | uvicorn |
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >3.5 | Python |
نحوه نصب
نصب پکیج whl coopapi-0.6:
pip install coopapi-0.6.whl
نصب پکیج tar.gz coopapi-0.6:
pip install coopapi-0.6.tar.gz