Skip to main content

pytyped-macros

pytyped-macros is a core piece of pytyped Python packages that allows analysis of a given Python type and its breakdown into primitive type combinators. In this way, pytyped-macros facilitate pytyped's main goal of type-driven development in Python. pytyped-macros is designed to be an extensible base class upon which other type derivations are implemented. In order to see examples of how pytyped-macros can be used, look at pytyped-json, and pytyped-metrics.

Installation

You can install pytyped-macros from PyPI:

pip install pytyped-macros

pytyped-macros is checked on Python 3.6+.

Why pytyped-macros?

To our knowledge, pytyped-macros is the only Python package that supports type-based automation for all typing constructs including even recursive types that, up to this day, are not even fully supported by Python itself. Additionally, pytyped-macros is designed to be extensible. That is, you can create a sub-class of pytyped-macros's Extractor class to automate type derivation for your own task. To see examples of how this is done in practice, look at pytyped-json which uses pytyped-macros in order to automatically derive JSON decoders/encoders for a given Python type.

Currently, pytyped-macros supports the following type driven derivations:

  • Derivations for basic types such as int, bool, date, datetime, str, and Decimal.
  • Derivations for simple usual combinators such as List[T] and Dict[A, B].
  • Derivations for named product types such as NamedTuples or dataclasses.
  • Derivations for anonymous product types such as Tuple[T1, T2, ...].
  • Derivations for anonymous union types such as Optional[T], Union[T1, T2, ...], etc.
  • Derivations for named union types such as class hierarchies (i.e., when a class A has several subclasses A1, ..., An).
  • Derivations for generic types and type variables.
  • Derivations for custom functional types such as Set[T], Secret[T], etc where a custom function is defined for generic types such as Set or Secret and that functional is applied to all instantiations of those generic type.
  • Derivations for recursive types such as binary trees, etc.

Defining New Type Automations

You can follow the examples of pytyped-json (for JSON decoders and JSON encoders), or pytyped-metrics for metric exporters to define new type-based automations. You just need to extend pytyped.macros.extractor.Extractor and implement the abstrtact methods there.

Issues

Please report any issues to the GitHub repository for this package.

Contributors

Release files for pytyped-macros 2.0.0

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

Source distribution (sdist)

Source distribution for pytyped-macros 2.0.0
File Size Uploaded
pytyped-macros-2.0.0.tar.gz 9.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytyped-macros 2.0.0
File Interpreter ABI Platform
pytyped_macros-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.3 kB

Release files / pytyped-macros-2.0.0.tar.gz

Download URL pytyped-macros-2.0.0.tar.gz
Size 9.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0380ccec13850fb3811a11a47ed7731beec6a24d6a9a702ab038341e8342f240
BLAKE2b-256 checksum
How to use checksums
5a28dfef4b9a115cc92b624344199b7a3df5e71b3396c7a9b3149e287585355d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.16

Release files / pytyped_macros-2.0.0-py3-none-any.whl

Download URL pytyped_macros-2.0.0-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6330f67e51df01dfb7327bdf2359afd68a9d2f36e3d1a5a3674b7ceb61f1d7e
BLAKE2b-256 checksum
How to use checksums
2a718ec89ed371ff0e900d8ac8b84a8fada1d5df6e6cb4c39d1fe3393d3eefa9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.16

Release history Release notifications | RSS feed

This release

2.0.0 This release

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