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/*

Download files

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

Source Distribution

jospy-0.2.0.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.

jospy-0.2.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file jospy-0.2.0.tar.gz.

File metadata

  • Download URL: jospy-0.2.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for jospy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7ef77684016fd4ce49bcb7c14300bd8b6cf2371a0b7548ab7b2bb131fd3547ee
MD5 9bcf64672615716afa5eea623a791778
BLAKE2b-256 8439d8ab42562a1013253160c6a86e4f471e8b056e0e79b268e8d3afe4268b94

See more details on using hashes here.

File details

Details for the file jospy-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: jospy-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for jospy-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1cb00cbce550db67fd9d5b4cc9f97c8c208ae3349a8027f27650dd28652d0bcc
MD5 0d8ac5291de61912184548d8926642ec
BLAKE2b-256 741276734120efcb030e9b160583142c9c0151614127585d4302c96f0fe021ac

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.0

2 files

Supported by

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