FastAPI Ultimate Toolkit
The most useful tools for any FastAPI project
Installation
pip install fastapi-utk
Features
- Api
- Pagination
- Pagination
- PaginationConfig
- Paginator
- Paginated
- Sorting
- Sorting
- SortingOption
- SortingConfig
- Middlewares
- CamelCaseQueryParamsMiddleware
- OpenAPI
- translate_query_params_snake_to_camel
- Pagination
- Utils
- NotSet
Use cases
>>> CLICK THE LINK TO SEE EXAMPLE PROJECT <<<
Pagination
Example
import typing as tp
from my_app import router
from my_app.response_models import User
from fastapi_utk import Paginated, Pagination, Paginator
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
@router.get("/foo")
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_query_param_name="fooPage", # query param name to set a page number
url_page_size_query_param_name="fooPageSize",
# query param name 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
# /foo?fooPage=1&fooPageSize=100
Sorting
Example
import typing as tp
from fastapi_utk import Sorting, SortingOption
from my_app import router
from my_app.response_models import User
sorting = Sorting()
@router.get("/users")
def get_users(
sort_by: tp.Annotated[list[SortingOption], sorting.Depends(["age", "name"], default=["-age"])],
) -> list[User]:
print(sort_by)
# [
# SortingOption(field="baz", is_desc=False),
# SortingOption(field="baz_baz", is_desc=True),
# ]
total, users = get_users_from_db(..., _sort_by=sort_by)
return [
User(
id=user.id,
age=user.age,
name=user.name,
)
for user in users
]
Extra
import typing as tp
from fastapi_utk import Sorting, SortingOption
# Use Sorting class to specify global pagination configuration
sorting = Sorting()
# If for some routes you need non-default configuration, set it right in depends
@router.get("/foo")
def foo(
sort_by: tp.Annotated[
list[SortingOption],
sorting.Depends(
choices=["bar", "baz_baz", "pop"], # allowed sorting keys, for example `my.api/path?sort=bar,-pop`
default=["-bar"], # default sorting return (if not set by request params)
delimiter=",", # sorting keys delimiter
url_query_param_name="sort" # query param name to set sorting
)
],
) -> ...:
...
# /foo?sort=baz,-barBaz
Metadata
Release files for fastapi-utk 1.0.3
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 |
|---|---|---|---|---|
| fastapi_utk-1.0.3.tar.gz | 22.2 kB | Without provenance | Details for fastapi_utk-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_utk-1.0.3-py3-none-any.whl | Python 3 | none | any | Details for fastapi_utk-1.0.3-py3-none-any.whl |
Total release size: 45.5 kB
Release files / fastapi_utk-1.0.3.tar.gz
| Download URL | fastapi_utk-1.0.3.tar.gz |
|---|---|
| Size | 22.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
985716bd8236e9351a8883ead7d4705317fad79e0866266d3796951e936ac4aa
|
|
BLAKE2b-256 checksum How to use checksums |
b868f31bd7ad7d74c3ea224d2df855be7740acf5a3d837b0528310218b1f664f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.29
|
Release files / fastapi_utk-1.0.3-py3-none-any.whl
| Download URL | fastapi_utk-1.0.3-py3-none-any.whl |
|---|---|
| Size | 23.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d0ad1c76d3b3db9b6f45c70a57b7d7bbcbc2c1fb1b01b8454f22a8800543530e
|
|
BLAKE2b-256 checksum How to use checksums |
50f0e886db9d08ef910035f7469217327f41aca7bd24079a0c677ffa7cf8a345
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.29
|
Security for fastapi-utk 1.0.3
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.