structional
Immutable structs, controlled randomness, and trees. These are the core tools that are ubiquitous to my style of writing Python. Now available in open source!
Whilst this library does not depend on PyTorch and is broadly applicable across all of Python, the downstream use-case is to make it possible to 'write functional PyTorch'.
This is not a library implementing monads, foldl, and all that magical Haskell stuff.
Installation
pip install structional
Documentation
Available at https://docs.kidger.site/structional.
What's in the box?
Struct:
- is an immutable (frozen) dataclass, making writing safe code easy;
- is an abstract base class, supporting the stdlib
abstractmethodand our own extensionsAbstractVar(declaring abstract attributes) and__check_init__(post-initialization invariants); - enforces 'abstract/final rules': every class can either be subclassed (abstract) or instantiated (concrete) – but not both.
PRNGKey provides access to deterministic randomness.
- Use-case in ML is perfectly reproducible training runs; awesome for catching bugs.
- A function need no longer be 'secretly random' because it depends on a background stateful RNG.
- Call
key.some_distribution()to sample from a distribution. - Split a key via
key.split()to create deterministic but statistically independent new sources of randomness. - Keys can only be used once (known as 'linear typing'), to prevent accidental reuse.
tree is a subpackage for manipulating immutable nested structures of tuples, Structs, etc.:
tree.map('functors' for you programming geeks) applies a function to every leaf.tree.replace('lenses' for the geeks) updates just part of a tree structure, returning a new object out-of-place.
Metadata
Release files for structional 0.5.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| structional-0.5.1.tar.gz | 28.0 kB | Without provenance | Details for structional-0.5.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| structional-0.5.1-py3-none-any.whl | Python 3 | none | any | Details for structional-0.5.1-py3-none-any.whl |
Total release size: 62.7 kB
Release files / structional-0.5.1.tar.gz
| Download URL | structional-0.5.1.tar.gz |
|---|---|
| Size | 28.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f97f7212d2c652ccbe91e8a4fc8b920ce81e469e53e63a3c5c9e1c0dd7290b4
|
|
BLAKE2b-256 checksum How to use checksums |
c5226a2090c3eb1003e3639ffc5955e2e19c560e1bee253bd0bdf704bb82b5c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Release files / structional-0.5.1-py3-none-any.whl
| Download URL | structional-0.5.1-py3-none-any.whl |
|---|---|
| Size | 34.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ef398849fd450ca043f65a641202263a0ab2ca57d49582ec2cf75f22355c6bd6
|
|
BLAKE2b-256 checksum How to use checksums |
e3c40f85b67eb128383ad99627d5c63b7c4c47468bf0740676b39f6f1d53e341
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Security for structional 0.5.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.