FastAPI Ultimate Toolkit
Project description
FastAPI Ultimate Toolkit
The most useful tools for any FastAPI project
Installation
pip install fastapi-utk
Features
- Api
- Pagination
- Pagination
- PaginationConfig
- Paginator
- Paginated
- Pagination
- Utils
- NotSet
Use cases
>>> CLICK THE LINK TO SEE EXAMPLE PROJECT <<<
Pagination
Example
import typing as tp
from fastapi_utk import Paginated, Pagination, Paginator
from my_app import router
from my_app.response_models import User
pagination = Pagination()
@router.get("/users")
def get_users(
paginator: tp.Annotated[Paginator, pagination.Depends()],
) -> Paginated[User]:
total, users = get_users_from_db(..., limit=paginator.limit, offset=paginator.offset)
return paginator(
[
User(
id=user.id,
age=user.age,
name=user.name,
)
for user in users
],
total=total,
)
Response
Schema
Extra
import typing as tp
from fastapi_utk import Paginated, Pagination, Paginator
# Use Pagination class to specify global pagination configuration
pagination = Pagination()
# If for some routes you need non-default configuration, set it right in depends
@route.get("")
def foo(
paginator: tp.Annotated[
Paginator,
pagination.Depends(
default_page=1, # default page number if query param is not set
default_page_size=10, # default page size if query param is not set
max_page_size=100, # maximum page size
url_page_param="fooPage", # query param to set a page number
url_page_size_param="fooPageSize", # query param to set page size, set `None` to disable this option
)
]
) -> Paginated[MyModel]: # use Paginated[...] to warp collection response
# ...
return paginator(..., total=...) # total is used to calculate amount of pages
# /users?fooPage=1&fooPageSize=100
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fastapi_utk-0.1.1.tar.gz
(16.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_utk-0.1.1.tar.gz.
File metadata
- Download URL: fastapi_utk-0.1.1.tar.gz
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67d66f2e47cc64d1e8653982c8363ae4dc5ead3fd8e0aee0a4a7ecd356deadee
|
|
| MD5 |
0cacf59d3c60879eb886e47227e5a951
|
|
| BLAKE2b-256 |
2fc4302e7f67ed516bfd7d66e825e97fbdcb7b547fe8c168ad84f21ffeab9f80
|
File details
Details for the file fastapi_utk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: fastapi_utk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e40646df0a7efee32c2c368fb4ed6bda48780cd887ec801609f4226b1cd8be58
|
|
| MD5 |
a0859d854cf101b15d73c33f61c5adeb
|
|
| BLAKE2b-256 |
a4283aa158e90f7c382031ef1567ee57e53f051a93bad770daa829d699df54e7
|