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/*
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ef77684016fd4ce49bcb7c14300bd8b6cf2371a0b7548ab7b2bb131fd3547ee
|
|
| MD5 |
9bcf64672615716afa5eea623a791778
|
|
| BLAKE2b-256 |
8439d8ab42562a1013253160c6a86e4f471e8b056e0e79b268e8d3afe4268b94
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cb00cbce550db67fd9d5b4cc9f97c8c208ae3349a8027f27650dd28652d0bcc
|
|
| MD5 |
0d8ac5291de61912184548d8926642ec
|
|
| BLAKE2b-256 |
741276734120efcb030e9b160583142c9c0151614127585d4302c96f0fe021ac
|