Skip to main content

returnz-fastapi

FastAPI integration for returnz. Python 3.14+.

Return a Result from your services; unwrap_or_raise at the route boundary. Ok values flow through as the success type; Err values become HTTP responses by the error's own status and tag (HttpError). The boundary stays invisible to the handler.

from typing import Literal

from fastapi import FastAPI
from returnz import Ok, Err, Result, do_async, require
from returnz_fastapi import HttpError, unwrap_or_raise


class NotFound(HttpError):
    status_code = 404
    tag: Literal["not_found"] = "not_found"
    id: str


async def fetch_user(user_id: str) -> Result[User, NotFound]:
    user = await db.get(user_id)
    return Ok(user) if user is not None else Err(NotFound(id=user_id))


@do_async
async def zip_of(user_id: str) -> Result[str, NotFound]:
    user = require(await fetch_user(user_id))  # ? on the Result
    return Ok(user.zip)


app = FastAPI()


@app.get("/users/{user_id}/zip")
async def get_zip(user_id: str) -> str:
    return unwrap_or_raise(await zip_of(user_id))
  • GET /users/42/zip200 "90210"
  • GET /users/99/zip404 {"detail": {"tag": "not_found", "id": "99"}}

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

returnz_fastapi-0.1.2.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

returnz_fastapi-0.1.2-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file returnz_fastapi-0.1.2.tar.gz.

File metadata

  • Download URL: returnz_fastapi-0.1.2.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for returnz_fastapi-0.1.2.tar.gz
Algorithm Hash digest
SHA256 34ec040ab89830d399f41653f23da0cf5492955311c4be2daa881a07ad0f3fde
MD5 6c761a3214e668e1495deb78c6a07a41
BLAKE2b-256 9d9610589f2d86a73c1bc57c2cb7d0aab0bede761f144b3356953aee5b69a90c

See more details on using hashes here.

File details

Details for the file returnz_fastapi-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: returnz_fastapi-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for returnz_fastapi-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 dc5528e6bf71162f419e942aa707f9b4c8b9dc45b4ed67a766a6d2a1e5356ffb
MD5 9815b93286de13c3c267f08a38a26aa0
BLAKE2b-256 8839f311cbb0853dc5c0759fc7be38c06af67bf6938cbf62d1e60cef0816ee69

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page