Skip to main content

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 Result for 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 via Result.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 Error values 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 as ErrorCategory.CANCELED vs. 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 when is_success is 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 raises ResultException.
  • 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 / none
  • null_or_empty
  • null_or_whitespace
  • out_of_range(value, min_val, max_val)
  • less_than, less_than_or_equal
  • greater_than, greater_than_or_equal
  • length_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.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nyssa-ai-result 0.2.3
File Size Uploaded Provenance Actions
nyssa_ai_result-0.2.3.tar.gz 14.9 kB With provenance Details for nyssa_ai_result-0.2.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nyssa-ai-result 0.2.3
File Interpreter ABI Platform Actions
nyssa_ai_result-0.2.3-py3-none-any.whl Python 3 none any Details for nyssa_ai_result-0.2.3-py3-none-any.whl

Total release size: 26.9 kB

Release files / nyssa_ai_result-0.2.3.tar.gz

Download URL nyssa_ai_result-0.2.3.tar.gz
Size 14.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d9cc2834f41cfb20828dcd2fd1d77717ca763877ec2391cff614850fd2edb92c
BLAKE2b-256 checksum
How to use checksums
b49892c10dadf0488f6c1c6f7a36e556f4e96d7580429ddc873822b925e64e98
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 log

Release files / nyssa_ai_result-0.2.3-py3-none-any.whl

Download URL nyssa_ai_result-0.2.3-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f51a76b5aa9576defb3463c23d9b4bef2b6aa4e6cf39bf8d0ad7ba721f0d9b7
BLAKE2b-256 checksum
How to use checksums
bbd2b9c561427941d640b69777da9f40f953a842be4c9238ccbff328c3ba66d2
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 log

Security for nyssa-ai-result 0.2.3

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.

Select from 2 files

Attestation for nyssa_ai_result-0.2.3.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 log

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.

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page