Skip to main content

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 (alias: stimestamp), IntTimestampDatetime (alias: itimestamp), FloatTimestampDatetime (alias: ftimestamp), ISODatetime (alias: isodatetime), and datetime.datetime.
  • timedelta — subclass of datetime.timedelta with cast support.
  • StrEnum, IntEnum, FloatEnum, Enum and EnumMeta — enum 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

  • Email — format: email
  • IDNEmail — format: idn-email
  • URI — format: uri
  • URIReference — format: uri-reference
  • IRI — format: iri
  • IRIReference — format: iri-reference
  • Hostname — format: hostname
  • IDNHostname — format: idn-hostname
  • IPv4 — format: ipv4
  • IPv6 — format: ipv6
  • JsonPointer — format: json-pointer
  • RelativeJsonPointer — format: relative-json-pointer
  • Regex — format: regex
  • Int32, Int64 — range-limited integer types
  • Float32, Float64 — finite, range-limited floating-point types
  • UUID4 — uuid v4

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

License

msgspex is MIT licensed

Metadata

Release files for msgspex 1.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for msgspex 1.7.1
File Size Uploaded
msgspex-1.7.1.tar.gz 31.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for msgspex 1.7.1
File Interpreter ABI Platform
msgspex-1.7.1-py3-none-any.whl Python 3 none any Details

Total release size: 77.7 kB

Release files / msgspex-1.7.1.tar.gz

Download URL msgspex-1.7.1.tar.gz
Size 31.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6abcdc8334f59fe54988f0629e40eb92b996f4c6c7c5e262569ccd32526f9bb9
BLAKE2b-256 checksum
How to use checksums
c9b5b4b400c7a7489049ecf7e2340d9180e4e227421c65e7ccc44f1f3e04e8ab
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.1-py3-none-any.whl

Download URL msgspex-1.7.1-py3-none-any.whl
Size 46.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
886468d56a26ddf558dec9e972d066fdbae487aa3bf32eb360beff8f2bf05768
BLAKE2b-256 checksum
How to use checksums
29cf1b4d711b43845beef85e8ccbbe0ce19a6f26689ae873c24499c75ec59ad8
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 history Release notifications | RSS feed

This release

1.7.1 This release

2 release files

1.7.0

2 release files

1.6.0

2 release files

1.5.4

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page