Skip to main content

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

Project description

msgspex

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

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.

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 is not redefined here, because it is already supported by msgspec.

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.0.1.tar.gz (24.6 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.0.1-py3-none-any.whl (37.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: msgspex-1.0.1.tar.gz
  • Upload date:
  • Size: 24.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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.0.1.tar.gz
Algorithm Hash digest
SHA256 c39d0d356312d0fdb8827e7b4126859c2f01254a61f8f246ed93e4fae584fdd4
MD5 bad48b5b4d608cf17cdfec00beacd209
BLAKE2b-256 5ec194ac162c6ede0489edf76bef75e87d14c92dd0155f458ee07db4a8e2b7cd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: msgspex-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 37.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f1cbe718e41c10cecd10ac7a6026b78f6230839a0e9e92097f74d96fae0f5550
MD5 4f86bfcc866625eec235f5f644138f7b
BLAKE2b-256 ca81ffd72dc2eb2b6d2b24cce58561eb9103279593f2f86a2e23f4aeebc9a9f7

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