Skip to main content

jospy

Documentation Status

jospy is a small Python utility package for JSON payloads and REST API responses. It uses Python's built-in json module and adds a friendlier layer for common backend work: JSON to Python, Python to JSON, null handling, default filling, filtering, nested paths, and response envelopes.

Install it locally while developing:

pip install -e ".[dev]"

Basic usage:

from jospy import api_response, fill, filter_data, null, to_json, to_python

payload = to_python('{"name": "Ada", "email": null}')
payload = fill(payload, {"active": True, "email": "unknown@example.com"})

public_payload = filter_data(payload, exclude=["password"], drop_nulls=True)
body = to_json(api_response(public_payload, message="ok"), pretty=True)

Chainable data layer:

from jospy import data

users = [
    {"id": 1, "name": "Ada", "team": "api", "email": None, "password": "secret"},
    {"id": 2, "name": "Grace", "team": "infra", "email": "g@example.com"},
]

body = (
    data(users)
    .where(team="api")
    .filter(exclude=["password"], drop_nulls=True)
    .api_response(message="ok")
    .to_json(pretty=True)
)

Highlights:

  • to_python() / from_json() convert JSON strings, bytes, or files to Python.
  • to_json() serializes Python data to compact or pretty JSON.
  • data() creates a chainable data layer for .fill().filter().api_response().
  • null() returns None with no arguments, or checks if values are None.
  • fill() recursively fills missing or None fields with defaults.
  • filter_data() filters dictionaries or lists by fields, predicates, and nulls.
  • pick() / omit() are quick field-selection helpers.
  • get_path() / set_path() work with nested dot paths like user.email.
  • api_response() and paginated() create consistent REST API response shapes.

REST API example:

from jospy import api_response, paginated


def get_user_response(user):
    return api_response(user, message="User loaded")


def list_users_response(users, page=1):
    return paginated(users, page=page, per_page=25)

Nested data example:

from jospy import data

payload = (
    data({})
    .set("user.profile.email", "ada@example.com")
    .set("user.active", True)
)

email = payload.get("user.profile.email").unwrap()

Documentation

Read the hosted docs at https://jospy.readthedocs.io/ or see docs/index.md locally for the full helper reference and examples.

Read the Docs setup notes live in docs/readthedocs.md.

Development

Run tests:

python -m pytest

Build the package:

python -m build
python -m twine check dist/*

Metadata

Release files for jospy 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 jospy 0.2.0
File Size Uploaded
jospy-0.2.0.tar.gz 7.3 kB Details

Built distribution (wheel)

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

Total release size: 15.8 kB

Release files / jospy-0.2.0.tar.gz

Download URL jospy-0.2.0.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7ef77684016fd4ce49bcb7c14300bd8b6cf2371a0b7548ab7b2bb131fd3547ee
BLAKE2b-256 checksum
How to use checksums
8439d8ab42562a1013253160c6a86e4f471e8b056e0e79b268e8d3afe4268b94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

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

Download URL jospy-0.2.0-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1cb00cbce550db67fd9d5b4cc9f97c8c208ae3349a8027f27650dd28652d0bcc
BLAKE2b-256 checksum
How to use checksums
741276734120efcb030e9b160583142c9c0151614127585d4302c96f0fe021ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.2.0 This release

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