FastAPI Ultimate Toolkit
Project description
FastAPI Ultimate Toolkit
The most useful tools for any FastAPI project
- 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(...)
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.0.tar.gz
(16.4 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.0.tar.gz.
File metadata
- Download URL: fastapi_utk-0.1.0.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c27ce2d22ddf60c303c90c27a672c5c2975aadf4a658f1e8eb807b00d5db2371
|
|
| MD5 |
c465668bc5dab8d16d2014262cddec89
|
|
| BLAKE2b-256 |
f071b407cb2503ae6f4275be84180d1dbffd4c58f322c246f1ec79ffe1353ce8
|
File details
Details for the file fastapi_utk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_utk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.3 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 |
8fd17bc33985e7cb574aef193a2654c1d5006a9dca2497fcb702587236ec0250
|
|
| MD5 |
dfdb7bcd016c62fc2dc3c48736226e37
|
|
| BLAKE2b-256 |
ef492aff2c2df2d2786bc59b6a4efea8c4ab7cdd6c5f4b77acea96f9056a7163
|