Skip to main content

pygoerrors

A Python library that brings Go-style error handling to Python, enabling error values, wrapping, and inspection without relying on exceptions.​

🚀 Features

  • Error Values: Return errors as values instead of raising exceptions.
  • Error Wrapping: Wrap errors with contextual messages, similar to Go's fmt.Errorf("...: %w", err).
  • Error Inspection: Traverse error chains using unwrap(), is_(), and as_().
  • Protocol-Based Design: Utilize Python's Protocol to define error interfaces.
  • No Exceptions: Emphasize functional programming by avoiding exceptions entirely.​

📦 Installation

Install the package using pip:

pip install pygoerrors

🧑‍💻 Usage

Defining Custom Errors

import pygoerrors

MyOtherError = pygoerrors.new("some error")

class MyErrorClass(pygoerrors.Error):
    def error(self) -> str:
        return "some error"

Wrapping Errors

import pygoerrors

class MyErrorClass(pygoerrors.Error):
    def error(self) -> str:
        return "base error"

base_err = MyErrorClass()
assert base_err.error() == "base error"

wrapped_err = pygoerrors.errorf("wrapped: %w", base_err)
assert wrapped_err.error() == "wrapped: base error"

Inspecting Errors

import pygoerrors

class MyErrorClass(pygoerrors.Error):
    def error(self) -> str:
        return "base error"

base_err = MyErrorClass()
assert base_err.error() == "base error"

wrapped_err = pygoerrors.errorf("wrapped: %w", base_err)
assert wrapped_err.error() == "wrapped: base error"

assert pygoerrors.is_(wrapped_err, MyErrorClass())

instance = pygoerrors.as_(err, MyErrorClass)
assert instance.error() == "base error"

Metadata

Release files for pygoerrors 0.2.0

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

Source distribution (sdist)

Source distribution for pygoerrors 0.2.0
File Size Uploaded
pygoerrors-0.2.0.tar.gz 29.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pygoerrors 0.2.0
File Interpreter ABI Platform
pygoerrors-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 59.9 kB

Release files / pygoerrors-0.2.0.tar.gz

Download URL pygoerrors-0.2.0.tar.gz
Size 29.0 kB
Tags Source
SHA-256 checksum
How to use checksums
96240980a00a0fe23af65c0b3eeb716c7f290d5a7ae156bf12ddfb7a08b2add7
BLAKE2b-256 checksum
How to use checksums
9f0df7ece90a9355044a5c0110fbf473bb74e226dd068b7710a937d9fbe49768
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Jun 12, 2025.

Transparency log

Release files / pygoerrors-0.2.0-py3-none-any.whl

Download URL pygoerrors-0.2.0-py3-none-any.whl
Size 30.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fe778fdbbde2140f666e7c2ed94da39a3c55b18f9f65aa732cf872b3e83689bd
BLAKE2b-256 checksum
How to use checksums
88360510a69240ea3409a7e26364ce3cea377e26312b0ad5c664f9fb6c3c198d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Jun 12, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

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