jospy
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()returnsNonewith no arguments, or checks if values areNone.fill()recursively fills missing orNonefields 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 likeuser.email.api_response()andpaginated()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)
| File | Size | Uploaded | |
|---|---|---|---|
| jospy-0.2.0.tar.gz | 7.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|