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 onkungfu(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 ofdatetime.date.datetime— meta-type that coversStringTimestampDatetime(alias:stimestamp),IntTimestampDatetime(alias:itimestamp),FloatTimestampDatetime(alias:ftimestamp),ISODatetime(alias:isodatetime), anddatetime.datetime.timedelta— subclass ofdatetime.timedeltawith cast support.StrEnum,IntEnum,FloatEnum,EnumandEnumMeta—enumextensions for stable handling of unknown values.Literal— runtime type conceptually compatible withtyping.Literal.dataclasses.InitVar— Passing vars to a__post_init__method.
3. OpenAPI-Oriented Types
Email—format: emailIDNEmail—format: idn-emailURI—format: uriURIReference—format: uri-referenceIRI—format: iriIRIReference—format: iri-referenceHostname—format: hostnameIDNHostname—format: idn-hostnameIPv4—format: ipv4IPv6—format: ipv6JsonPointer—format: json-pointerRelativeJsonPointer—format: relative-json-pointerRegex—format: regexInt32,Int64— range-limited integer typesFloat32,Float64— finite, range-limited floating-point typesUUID4— uuid v4
UUID, Decimal, date and time already supported by msgspec.
License
msgspex is MIT licensed
Metadata
Release files for msgspex 1.7.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 | |
|---|---|---|---|
| msgspex-1.7.0.tar.gz | 31.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| msgspex-1.7.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 77.6 kB
Release files / msgspex-1.7.0.tar.gz
| Download URL | msgspex-1.7.0.tar.gz |
|---|---|
| Size | 31.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
930ec71c4d5ef0cbae2ffbfe1382c7e3657d4d6c0d87f370515a8e23e86a099b
|
|
BLAKE2b-256 checksum How to use checksums |
edc7b913a42e1c5d097ed2bf5d0fd44421b6752f0d72a8e7eeb6db0e89142f5a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","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}
|
Release files / msgspex-1.7.0-py3-none-any.whl
| Download URL | msgspex-1.7.0-py3-none-any.whl |
|---|---|
| Size | 46.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d35a1bd0856f69c6d62a23604514dfd74cbe3e6c96ce1b1988a3d69d34314f20
|
|
BLAKE2b-256 checksum How to use checksums |
54d81d1cfe3126ba57ef4a67d6732d0fdb87aa5b980fa55d666f780983f23add
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","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}
|