snekok
Small, typed tools for treating expected failures as values in Python.
from snekok.result import Err, Ok, Result
def parse_port(raw: str) -> Result[int, str]:
if raw.isdecimal():
return Ok(int(raw))
return Err("port must be an integer")
port = parse_port("8080")
if isinstance(port, Err):
print(port.error)
else:
print(port.unwrap())
The Result API deliberately stays small: Ok, Err, Result, unwrap,
unwrap_error, and the map, map_error, and_then, and and_then_async
composition methods required by concrete consumers. It does not attempt to provide a
functional-programming framework.
Validated scalar aliases
NonEmptySecretStr, NonEmptyStr, and NonNegativeInt are constrained nominal
aliases with Pydantic support:
from pydantic import BaseModel
from snekok.types import NonEmptySecretStr, NonEmptyStr, NonNegativeInt
from snekok.validation import validate_python
class ApiSettings(BaseModel):
api_key: NonEmptySecretStr
label = validate_python(NonEmptyStr, "hello").unwrap()
retry_count = validate_python(NonNegativeInt, 0).unwrap()
settings = ApiSettings.model_validate({"api_key": "secret-value"})
assert settings.api_key.get_secret_value() == "secret-value"
Pydantic rejects an empty value. Static type checkers also reject an ordinary
SecretStr where NonEmptySecretStr is required, preventing unvalidated secrets
from crossing the typed boundary.
See docs/result.md for the Result contract. Pinned design references
for dmmulroy/better-result and dry-python/returns live in
docs/research/.
Release files for snekok 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| snekok-0.1.0.tar.gz | 31.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| snekok-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 35.8 kB
Release files / snekok-0.1.0.tar.gz
| Download URL | snekok-0.1.0.tar.gz |
|---|---|
| Size | 31.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d21359e4209a952360a886b75c6ded2e914e4104a68ea231cb3abe6ae1d9eece
|
|
BLAKE2b-256 checksum How to use checksums |
695c42e933eae19a717097f403ce759d8e4989eda1c18fa62067026aaf68e34c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","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 / snekok-0.1.0-py3-none-any.whl
| Download URL | snekok-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b81f126882ce9005c8dd8000d2c8401ca4addb091a8e661b36ab6903ded77fd1
|
|
BLAKE2b-256 checksum How to use checksums |
fbef5a8f332e9386bcaee2fa009c16d846a1d248a800db480cb2916cdda4e133
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|