apistar-pydantic
Better handler parameters for APIStar (and pydantic support).
General usage is working as expected but documentation and OpenAPI schema aren’t done yet.
$ pip install apistar-pydantic
Usage
from apistar import App
from pydantic import BaseModel
from apistar_pydantic import (
QueryParam, PathParam, DictBodyData, DictQueryData,
PydanticBodyData as BodyData,
PydanticQueryData as QueryData,
Route, components,
)
#
# Declare models
#
class City(BaseModel):
"""City info"""
name: str
population: int
class Computer(BaseModel):
"""Computer info"""
model: str
price: float
class ComputerCity(City, Computer):
"""A computer in a city"""
#
# Create views
#
def resource_complete(param1: QueryParam[str],
param2: QueryParam[int],
param3: DictBodyData[dict],
param4: DictQueryData[dict]):
return repr(locals())
def resource_query(city: QueryData[City]):
return "%s has %d citizens." % (city.name, city.population)
def resource_body(computer: BodyData[Computer]):
return "%s costs R$ %.2f" % (computer.model, computer.price)
def resource_mixed(city: QueryData[City],
computer: BodyData[Computer]):
return ComputerCity(**city.dict(), **computer.dict())
#
# Start the app
#
app = App(
routes=[
Route('/resource', 'GET', resource_query),
Route('/resource_query', 'GET', resource_query),
Route('/resource_body', 'POST', resource_body),
Route('/resource_mixed', 'POST', resource_mixed),
],
components=[
*components
]
)
if __name__ == '__main__':
app.serve('127.0.0.1', 3000, debug=True)
Metadata
Release files for apistar-pydantic 0.1.0
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 |
|---|---|---|---|---|
| apistar-pydantic-0.1.0.tar.gz | 196.7 kB | Without provenance | Details for apistar-pydantic-0.1.0.tar.gz |
Release files / apistar-pydantic-0.1.0.tar.gz
| Download URL | apistar-pydantic-0.1.0.tar.gz |
|---|---|
| Size | 196.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bdd429465b307c91ad5e196b3364c805747b2bf3d8159830f6b364a23641c040
|
|
BLAKE2b-256 checksum How to use checksums |
f500396c536aee6facfba53fd67c1cfc5e17f5511773e99f80ff772d22ce063f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for apistar-pydantic 0.1.0
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.