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.4.tar.gz (7.3 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.4-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: returnz_fastapi-0.1.4.tar.gz
  • Upload date:
  • Size: 7.3 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.4.tar.gz
Algorithm Hash digest
SHA256 ecb49f1aa225c046930bf2c0a13809d35adc876f42629c933f81213206bd35a2
MD5 6f92e2d6536f6340ab3798d10885be83
BLAKE2b-256 23e72b1e26f5383c2f6f3f3ce7d88c3dab2faeb91f0a9af93b9a892b8302900d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: returnz_fastapi-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 7.5 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 716abdc925ab627c8c8e967156ea21a5d7ed1c05a7c51d033f5077bf7ef3e31b
MD5 5561e376208b15d0cec8aa3ac447dcf3
BLAKE2b-256 423aadbb5e49a78f46cc2026df944eaf4f31605eb0aa72d878fc88ba12ea47fb

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