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.0.tar.gz (6.5 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.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: returnz_fastapi-0.1.0.tar.gz
  • Upload date:
  • Size: 6.5 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.0.tar.gz
Algorithm Hash digest
SHA256 f05436a7897f8601013cc0a854e7f1d807a7785109ea5d6d83e97f2fde18bc0a
MD5 9750ed75d88a506d634de117f5fe152c
BLAKE2b-256 cbd3620cf5e3d4e30353895707eb3a7bdeb42021b1adb0ae071770a28053ce1a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: returnz_fastapi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.9 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 75f041e818a907076ca83764ba222e1321425fa3b96ca7fc94ae004a4f84ecfc
MD5 bf4bf9e586459d43dfefeb99063865df
BLAKE2b-256 db8fbaf2919e379f5908aac18c90a1f988b97516f8c42d1bb7df4dcda6a09f83

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