NyssaAI.Result (Python)
nyssa-ai-result gives Python applications a consistent way to report whether an operation succeeded and, when it did not, what went wrong. A function returns Result[T] holding either the successful payload or structured errors.
The library implements Railway-Oriented Programming (ROP) with pure combinators and explicit exception boundaries, adhering to Jeremy Maynor's dev-standards (v0.6.5).
Core Invariant: Pure Combinators vs. Explicit Exception Boundaries
Fail fast on programmer defects; use
Resultfor expected operational outcomes. Unexpected exceptions (e.g.,AttributeError,ZeroDivisionError,KeyError, coding defects) bubble immediately. External fallible I/O (e.g., HTTP drivers, database adapters) must be wrapped exclusively at explicit boundaries viaResult.try_/Result.try_async.
1. Pure Monadic Combinators (then, then_async, transform, transform_async)
Monadic chaining methods do not swallow or intercept unexpected exceptions in delegates:
- If the current result is a failure, errors propagate immediately without executing the delegate.
- If the current result is a success, the delegate is executed directly. Any unexpected exception bubbles up the stack immediately so unit tests and telemetry identify the defect immediately.
2. Explicit Exception Boundaries (Result.try_, Result.try_async)
Volatile, external fallible boundaries catch exceptions and convert them into structured failures:
- Standard translation maps exceptions to
Errorvalues while preserving the causal chain and stack trace. - Custom error handlers (
error_handler: Callable[[Exception], Error]) allow translation to specific categories. - Cancellation evidence (
asyncio.CancelledError,TimeoutError, cancellation tokens) classifies outcomes accurately asErrorCategory.CANCELEDvs.ErrorCategory.UNAVAILABLE.
Quickstart
from nyssa_ai_result import Error, ErrorCategory, Guard, Result, ok, fail
# 1. Success and Failure factories
res_ok = Result.success(42)
res_fail = Result.failure(Error.from_message("Entity not found", ErrorCategory.NOT_FOUND))
# Shorthand helpers
s = ok("payload")
f = fail("something broke")
# 2. Inspecting results
if res_ok:
print(f"Value: {res_ok.value}")
if res_fail.is_failure:
for err in res_fail.errors:
print(f"[{err.category}] {err.user_message}: {err.technical_message}")
# 3. Monadic Chaining (Railway-Oriented Pipeline)
pipeline_result = (
Guard.against.null_or_whitespace(username, parameter_name="username")
.then(lambda valid_name: find_user(valid_name))
.transform(lambda user: user.to_dto())
)
# 4. Explicit Exception Boundary for External I/O
db_result = Result.try_(
lambda: database_driver.query_user(user_id),
error_handler=lambda exc: Error.from_messages(
user_message="Database service currently unavailable.",
technical_message=f"Driver failure: {exc}",
category=ErrorCategory.UNAVAILABLE,
)
)
API Overview
Result[T]
value: T: The success payload (meaningful only whenis_successis True).errors: tuple[Error, ...]: Structured failures (empty on success).is_success / ok: bool: True on success, False on failure.is_failure: bool: True on failure, False on success.then(next_op: Callable[[T], Result[U]]) -> Result[U]: Monadic bind (synchronous).then_async(next_op: Callable[[T], Awaitable[Result[U]]]) -> Result[U]: Monadic bind (asynchronous).transform(fn: Callable[[T], U]) -> Result[U]: Functor projection map (synchronous).transform_async(fn: Callable[[T], Awaitable[U]]) -> Result[U]: Functor projection map (asynchronous).resolve(on_success, on_failure) -> R: Fold / match into a unified value.resolve_async(on_success, on_failure) -> R: Async fold / match.throw_if_error() -> T/unwrap() -> T: Returns payload on success, or raisesResultException.try_get_value() -> tuple[bool, T | None]: Safe extraction tuple.try_(action, error_handler=None, cancellation_token=None): Synchronous explicit boundary.try_async(action, error_handler=None, cancellation_token=None): Asynchronous explicit boundary.
Error
user_message: str: Message safe for end users.technical_message: str | None: Diagnostic details, exception types, and chained causes.category: ErrorCategory: Categorization (UNEXPECTED,VALIDATION,NOT_FOUND,CONFLICT,FORBIDDEN,UNAVAILABLE,CANCELED,INDETERMINATE).stack_trace: str | None: Captured traceback if created from an exception.- Named factories:
from_message,from_messages,from_exception,from_exceptions,canceled,from_cancellation,from_caught,at_least_one.
Guard.against
Input validation guards returning Result[T] with ErrorCategory.VALIDATION:
null/nonenull_or_emptynull_or_whitespaceout_of_range(value, min_val, max_val)less_than,less_than_or_equalgreater_than,greater_than_or_equallength_out_of_range(string, min_len, max_len)pattern_mismatch(string, pattern)true(cond / value, predicate)false(cond / value, predicate)contains(collection, predicate)not_contains(collection, predicate)
Metadata
Release files for nyssa-ai-result 0.2.2
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 |
|---|---|---|---|---|
| nyssa_ai_result-0.2.2.tar.gz | 14.9 kB | With provenance | Details for nyssa_ai_result-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nyssa_ai_result-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for nyssa_ai_result-0.2.2-py3-none-any.whl |
Total release size: 26.9 kB
Release files / nyssa_ai_result-0.2.2.tar.gz
| Download URL | nyssa_ai_result-0.2.2.tar.gz |
|---|---|
| Size | 14.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fc19649ce6b7754bf8eb21aba4ae5742f9f671fc41598ae408605c1237ffbb5f
|
|
BLAKE2b-256 checksum How to use checksums |
2fd4b32285fddbc901bafe7d6c9f2558fa6c6d561e0255dcc2efc828970a1855
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.
Transparency logRelease files / nyssa_ai_result-0.2.2-py3-none-any.whl
| Download URL | nyssa_ai_result-0.2.2-py3-none-any.whl |
|---|---|
| Size | 12.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4c6d7cfabbbd5c41f36cc4b49807a54dfc2fc45fd068e1738b4305ecb3f4986b
|
|
BLAKE2b-256 checksum How to use checksums |
a0c5034177f88552d56baf9e0d525cb226b49707a140bfa4fa40fe5c7db295d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.
Transparency logSecurity for nyssa-ai-result 0.2.2
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for nyssa_ai_result-0.2.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 2, 2026.
Transparency logA 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.