Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

benzene-pydantic

Validate a Benzene handler's request with a pydantic model — the Python ecosystem's standard for parsing and validating request data — for the Benzene Python port.

Depends on benzene-core and pydantic. The core stays pydantic-free; this optional adapter is the one place the dependency lives.

pip install benzene-pydantic
from benzene.core import message
from benzene.pydantic import validated
from benzene.results import Result
from pydantic import BaseModel

class PlaceOrder(BaseModel):
    sku: str
    quantity: int = 1

@message("orders:place")          # no request_type — the raw body flows in and @validated checks it
@validated(PlaceOrder)
async def place(order: PlaceOrder) -> Result:
    return Result.created(order)  # a pydantic model returned as payload serializes on the wire

@validated(Model) validates the decoded body into Model before your handler runs. A pydantic.ValidationError becomes a validation-error Result that names each bad field, so a malformed request never reaches your handler and never crashes the pipeline:

# POST {"quantity": "not-an-int"}  ->  status "validation-error"
#   detail: "sku: Field required, quantity: Input should be a valid integer, ..."

A pydantic model returned as a success payload is serialized by benzene.core's wire mapper (model_dump(by_alias=True)). Unlike a dataclass — whose fields the mapper auto-camelCases — a pydantic model is dumped under its own field names, so give the model a camelCase alias_generator to cross the wire in the Benzene naming policy (then it matches a dataclass response).

Contributes the benzene.pydantic subpackage to the shared benzene namespace.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

benzene_pydantic-0.1.0b1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

benzene_pydantic-0.1.0b1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file benzene_pydantic-0.1.0b1.tar.gz.

File metadata

  • Download URL: benzene_pydantic-0.1.0b1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for benzene_pydantic-0.1.0b1.tar.gz
Algorithm Hash digest
SHA256 d4b70637323732648c230f5985642edab980b3bab93a0c37b0406c4331460000
MD5 cc087f79f6b4e42a3f2afd010a2527fe
BLAKE2b-256 b720d67f1568571e468cb0cb70286759de1fa02d27c85bbb886530e90eed2898

See more details on using hashes here.

Provenance

The following attestation bundles were made for benzene_pydantic-0.1.0b1.tar.gz:

Publisher: release.yml on daniellepelley/benzene-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file benzene_pydantic-0.1.0b1-py3-none-any.whl.

File metadata

File hashes

Hashes for benzene_pydantic-0.1.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 05a73a9787b4bd0c24538baac728db66b7ba9eebc798b9ab30423984e3267b60
MD5 abcfa96ad2be00c6d271fc063a5f6373
BLAKE2b-256 3ae66f086b408545d6fd5c4740b66759acb7061dd60e9d9212e8b7aefd04c90f

See more details on using hashes here.

Provenance

The following attestation bundles were made for benzene_pydantic-0.1.0b1-py3-none-any.whl:

Publisher: release.yml on daniellepelley/benzene-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0b1 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page