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 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,IntTimestampDatetime,FloatTimestampDatetime,ISODatetime(alias:isodatetime), anddatetime.datetime.timedelta— subclass ofdatetime.timedeltawith cast support.StrEnum,IntEnum,FloatEnum,BaseEnumMeta—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 types
UUID, Decimal, date and time already supported by msgspec.
License
msgspex is MIT licensed
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file msgspex-1.3.0.tar.gz.
File metadata
- Download URL: msgspex-1.3.0.tar.gz
- Upload date:
- Size: 28.2 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1746f495c8c4a5e80bf22568d41d63dcbb2e085ff687d1576f19efd6abb8fbc
|
|
| MD5 |
7ecd80bd1b13e0f4f53e8b0e804a7d60
|
|
| BLAKE2b-256 |
c7a5ecbbf0abe34be4fb63c5d62e979f368c48b05606d2f386459549e9c88b15
|
File details
Details for the file msgspex-1.3.0-py3-none-any.whl.
File metadata
- Download URL: msgspex-1.3.0-py3-none-any.whl
- Upload date:
- Size: 42.0 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79fa284bbe557e1a4b1cdd5a2a2a51751aff14c759edc16f85f42b8d4960d1e5
|
|
| MD5 |
7405a99a486a569278c5c2149fa33ccb
|
|
| BLAKE2b-256 |
57011281e227f49d21d3ff25c466f9cdbfb9ae954f93abd91cfb3c0bd321adda
|