Skip to main content

A small, typed JSON frame (envelope) for API responses and messages.

Project description

jsonframe

A tiny, opinionated helper for consistent JSON API response frames.

jsonframe standardizes how APIs return successful responses, collections, pagination metadata, and errors — without dragging in heavy specs or forcing a framework.


Design goals

  • Responses are always JSON objects (never top-level arrays)
  • Predictable structure across services
  • Minimal cognitive load for newcomers
  • No success: true flags — HTTP status codes already exist
  • Small enough to understand in one sitting

Core response rules

Success

{
  "data": ...,
  "meta": { ... }
}
  • data contains the business payload (object, list, scalar, or null)
  • meta contains non-business metadata (optional, always an object)

Error

{
  "error": {
    "code": "not_found",
    "message": "User not found",
    "details": { ... },
    "trace_id": "..."
  },
  "meta": { ... }
}
  • Errors are represented by a single error object
  • HTTP status code communicates severity
  • details and meta are optional

Installation

Core package

uv add jsonframe

Required dependency:

  • pydantic >= 2.0

Optional FastAPI integration

FastAPI helpers are optional and not installed by default.

uv add "jsonframe[fastapi]"

This installs:

  • fastapi
  • starlette

Usage

Success response

from jsonframe import ok

return ok({"id": 1, "name": "Ada"})

Empty success

from jsonframe import ok

return ok()

List response

from jsonframe import list_ok

return list_ok([{"id": 1}, {"id": 2}])

Paginated list

from jsonframe import paged

return paged(
    items=[{"id": 1}, {"id": 2}],
    total=120,
    limit=20,
    offset=40,
)

Result:

{
  "data": [...],
  "meta": {
    "page": {
      "total": 120,
      "limit": 20,
      "offset": 40
    }
  }
}

Error response

from jsonframe import fail

return fail(
    code="validation_error",
    message="Invalid input",
    details={"field": "email"},
)

FastAPI helpers (optional)

Returning framed JSON with status code

from jsonframe.fastapi import json
from jsonframe import ok

return json(ok({"id": 1}), status_code=200)

Raising framed HTTP errors

from jsonframe.fastapi import http_error

raise http_error(
    404,
    code="not_found",
    message="User not found",
    details={"user_id": 42},
)

What jsonframe is not

  • Not a full JSON:API implementation
  • Not a validation framework
  • Not a transport abstraction
  • Not a replacement for OpenAPI or HTTP semantics

When to use jsonframe

  • Internal APIs
  • BFFs
  • Microservices
  • AI / LLM-backed services
  • Teams that want consistency without ceremony

Philosophy

jsonframe is intentionally small.

It standardizes structure, not business logic.
If you can’t explain your API responses by pointing to this README, the library is doing too much.


License

MIT

Project details


Download files

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

Source Distribution

jsonframe-0.0.2.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

jsonframe-0.0.2-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file jsonframe-0.0.2.tar.gz.

File metadata

  • Download URL: jsonframe-0.0.2.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for jsonframe-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a61c96ef793dd3ae8b78b70e3245d1b801da3d6b6b88fc6f4de5ad3982b28313
MD5 9ff437cc548c5c4c2023be63eb8999bc
BLAKE2b-256 55b5085c811bf79f19c64bcdbfd152f7e4b7b69f48867bb328124d77f451316e

See more details on using hashes here.

File details

Details for the file jsonframe-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: jsonframe-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for jsonframe-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 55ff9eb3c2225eb05f748e2774aba83faa8ac57d7cdf814e11ea76888d7f4d47
MD5 492d4e4a2907db252e660f4893bdeb73
BLAKE2b-256 f51c00cfa316acafca2c14f65017bc17322f5238adc333461ba0881185a26e36

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 Pingdom Monitoring Sentry Error logging StatusPage Status page