Serpentine Oxidation: Rusty abstractions for Python.
Project description
Serox
Rusty abstractions for Python
serox
provides a suite of commonly-used Rust abstractions in a manner that is near-fully
static-type-checker compliant, the exceptions being cases involving higher-kinded types (HKTs; e.g.
Iterator.collect
) as these are not currently supported by Python's type system.
The subset of abstractions most broadly-applicable are importable from serox.prelude
.
Features
-
Iterator
combinators that allow for the seamless chaining of operations over data with rayon-inspired functionality for effortless parallelism. -
A
Result
pseudo-enum
comprisingSome
andNull
pseudo-variants. We say 'pseudo' as the Python analogue to Rust's tagged union is the union (A | B
) type; since this type is not a data structure, we cannot implement methods on it directly and instead have to resort to some legerdemain. -
An
Option
pseudo-enum
. TheT | None
pattern is ubiquitous in Python yet, frustratingly, is not treated as a first-class citizen within the language;Option
is a drop-in replacement that redresses this. -
The
qmark
decorator emulates the '?' (error/null short-circuiting) operator, allowing for propagation of error and null values without disrupting the control flow. Without this, one has to resort to awkward pattern-matching to perform common operations such asunwrap_or
(settingNull
to a default value) ormap
(applying a function to the contained value ifSome
).
Example
Early exiting (in the fashion of Rust's ?
operator) an Option/Result-returning function is enabled
by the qmark
('question mark') decorator:
from serox.prelude import *
@qmark
def some_function(value: Option[int]) -> Option[float]:
squared: int = value.map(lambda x: x ** 2).q
# The above expands to the rather verbose:
# match value:
# case Null():
# return Null[float]()
# case Some(x):
# squared = value ** 2
return Some(1.0 / squared)
Requirements
Python version >=3.12.3
is required for typing purposes.
Installation
serox
is available on PyPI and thus the latest version can be installed via pip
with
pip install serox
or via uv with
uv add serox
Acknowledgements
Credit to result and
rustshed for laying the groundwork for the Result
and
qmark
implementations.
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
File details
Details for the file serox-0.1.2.tar.gz
.
File metadata
- Download URL: serox-0.1.2.tar.gz
- Upload date:
- Size: 46.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cc2568c711a7c9407b0f416b16a3e01fc41a94dabde7c0c0963e92b6ae59d67 |
|
MD5 | a361e41727f5076d2ab63f05ca4715fa |
|
BLAKE2b-256 | 49288b5365308345ecc090b1e25bcf508398824a4731eadaa12cd8982cb14ebf |
File details
Details for the file serox-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: serox-0.1.2-py3-none-any.whl
- Upload date:
- Size: 27.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0740ba996f9e0bc673473db19f2960d0852c4120dd363cdb7dd4bafcfc10f785 |
|
MD5 | a4a5693d13434f17aff6064a5e559e2d |
|
BLAKE2b-256 | 5216c008ffbc9c8b43ab82a2f3bbb804e0c1867b34382a3710a3c53ba848c37c |