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
-
Iteratorcombinators that allow for the seamless chaining of operations over data with rayon-inspired functionality for effortless parallelism. -
A
Resultpseudo-enumcomprisingSomeandNullpseudo-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
Optionpseudo-enum. TheT | Nonepattern is ubiquitous in Python yet, frustratingly, is not treated as a first-class citizen within the language;Optionis a drop-in replacement that redresses this. -
The
qmarkdecorator 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(settingNullto 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
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 serox-0.1.3.tar.gz.
File metadata
- Download URL: serox-0.1.3.tar.gz
- Upload date:
- Size: 44.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7752217deada6b59fd3d95391219e87703a6fd813aeb460cbc7653566b9bda89
|
|
| MD5 |
29affa86fb63907f24ad4debe5091799
|
|
| BLAKE2b-256 |
bfecc0ee8f2ef9f69a1781b95a6020f5b46b089e8582d5dee8c7a6d7ae47a525
|
File details
Details for the file serox-0.1.3-py3-none-any.whl.
File metadata
- Download URL: serox-0.1.3-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 |
f77081b3d4d2580963d2d1521edab712d9bc0172d285f09664a86247ae1b3da3
|
|
| MD5 |
da5769c0dd578f306fd024b2b3e7f5b5
|
|
| BLAKE2b-256 |
80ae808f4575a181c4a2ab2b58b3d552f04ace9eab8d596a907b4df0f3576616
|