1、install
pip install fastapi_extend
2、use
from sqlalchemy import Column, String, Integer, Float, DateTime
from sqlalchemy.ext.declarative import declarative_base # ORM(对象关系映射)的基类
Base = declarative_base()
from fastapi_extend.serializer import Serializer
class Trade(Base):
__tablename__ = "trade"
id = Column(Integer, primary_key=True)
account = Column(String(20), default=None, nullable=False)
trade_datetime = Column(DateTime)
volume = Column(Float, default=None, nullable=False)
price = Column(Float, default=0, nullable=False)
order_id = Column(String(20))
class TradeSer(Serializer):
account: str
trade_datetime = Column(DateTime)
volume: float
price: float
order_id: str
1)、Pagination
from fastapi_extend.pagenator import PageNumberPagination
from pydantic import validator
from sqlalchemy import Column, String, Integer, Float, DateTime
paginator = PageNumberPagination(
params,
Trade,
TradeSer,
exclude={"start", "end"},
)
query = paginator.get_queryset()
if params.start:
query = query.where(Trade.trade_datetime >= params.start)
if params.end:
query = query.where(Trade.trade_datetime <= params.end)
data = await paginator.paginate_query(query, session)
2)、Serializer
from fastapi_extend.serializer import Serializer
from pydantic import validator
class TradeSer(Serializer):
account: str
volume: float
price: float
order_id: str
@validator("price")
def price_add(cls, v):
return v + 10
data_ser = TradeSer.dump(result.scalars(), many=True)
Metadata
Release files for fastapi-extend 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_extend-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for fastapi_extend-0.1.3-py3-none-any.whl |
Release files / fastapi_extend-0.1.3-py3-none-any.whl
| Download URL | fastapi_extend-0.1.3-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dd5d65d6dbc4c2e0c7439530a0593a0807244513f6f7bbbb41584a19745867be
|
|
BLAKE2b-256 checksum How to use checksums |
3cccabe6bb9ba2b1e299a4fe7ef4446550f4ec373fd34a2143b0764cb6f30e04
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.13
|
Security for fastapi-extend 0.1.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.