Skip to main content

An extra msgspec collection of custom types, casters, encode hooks, decode hooks and deprecation system.

Project description

msgspex

A collection of msgspec extensions: custom types, cast helpers, decode hooks, encode hooks and deprecation system.

Quick Start

import msgspex
from msgspex.custom_types import Email, datetime

value = msgspex.decoder.decode('"user@example.com"', type=Email)
dt = msgspex.decoder.decode('"2024-01-02T03:04:05Z"', type=datetime)
payload = msgspex.encoder.encode(dt)

Installing

pip install msgspex
uv add msgspex
poetry add msgspex

After import msgspex, all hooks and types are registered automatically.

Custom Types

1. Types from kungfu

  • Option[T] — optional value type based on kungfu (Some | Nothing | msgspec.UnsetType).

There is also decode-hook integration for kungfu.Sum (not a custom type, but supported by the decoder).

2. Types Derived from stdlib

  • date — re-export of datetime.date.
  • datetime — meta-type that covers StringTimestampDatetime, IntTimestampDatetime, FloatTimestampDatetime, ISODatetime (alias: isodatetime), and datetime.datetime.
  • timedelta — subclass of datetime.timedelta with cast support.
  • StrEnum, IntEnum, FloatEnum, BaseEnumMetaenum extensions for stable handling of unknown values.
  • Literal — runtime type conceptually compatible with typing.Literal.
  • dataclasses.InitVar — Passing vars to a __post_init__ method.

3. OpenAPI-Oriented Types

  • Emailformat: email
  • IDNEmailformat: idn-email
  • URIformat: uri
  • URIReferenceformat: uri-reference
  • IRIformat: iri
  • IRIReferenceformat: iri-reference
  • Hostnameformat: hostname
  • IDNHostnameformat: idn-hostname
  • IPv4format: ipv4
  • IPv6format: ipv6
  • JsonPointerformat: json-pointer
  • RelativeJsonPointerformat: relative-json-pointer
  • Regexformat: regex
  • Int32, Int64 — range-limited integer types
  • Float32, Float64 — finite, range-limited floating-point types

UUID, Decimal, date and time already supported by msgspec.

License

msgspex is MIT licensed

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

msgspex-1.5.1.tar.gz (29.4 kB view details)

Uploaded Source

Built Distribution

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

msgspex-1.5.1-py3-none-any.whl (43.2 kB view details)

Uploaded Python 3

File details

Details for the file msgspex-1.5.1.tar.gz.

File metadata

  • Download URL: msgspex-1.5.1.tar.gz
  • Upload date:
  • Size: 29.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for msgspex-1.5.1.tar.gz
Algorithm Hash digest
SHA256 74c7cb873c78578321bfcb1114dc4f94b49658f4233748158de448d811440df5
MD5 ca5ca6dbf34f622c41de1028ded98cf2
BLAKE2b-256 4141edf483443e16de65110bb6b7d09ba247af242a0380706eead82e0289b70a

See more details on using hashes here.

File details

Details for the file msgspex-1.5.1-py3-none-any.whl.

File metadata

  • Download URL: msgspex-1.5.1-py3-none-any.whl
  • Upload date:
  • Size: 43.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for msgspex-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 30e19e8b80fe7d4f8fe9548eef67e3cd9231406e7124f164e30bc176ac2f1295
MD5 bdfa5c3f771a95f566f0c3ae619560a6
BLAKE2b-256 262adad0b1d4f8a4b2d2130a39f460e333630a1b6873b60d2c888400b39191d1

See more details on using hashes here.

Supported by

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