This project has been archived by its maintainers, and is no longer receiving any updates.
apjson
apjson is an asynchonus prettifier for json-like objects and a simple implementation of the json module and decorators.
Installation
Install via pip:
pip install apjson
Example
from apjson import prettify, to_bytesio, jbytesio, jpretty
import asyncio
@jbytesio(sort_keys=True, check_circular=True)
def sync_json():
return '{"in": "this", "example": "the", "json": "function", "is": "sync"}'
@jpretty(silent=True)
async def async_json():
return "{\"instead\": \"here\", \"is\": \"async\"}"
async def main():
print((await to_bytesio('{"this": "is", "an": "example", "here": 123}')).read())
print(await prettify('{"this": "is", "another": "example", "here": True}'))
print(await prettify(b"{\"X\": 123}"))
print(await prettify(bytearray("{\"X\": 123}", encoding='utf-8')))
#every decorated function should be awaited (even sync)
print((await sync_json()).read())
print(await async_json())
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Prettifier
prettify: Prettifies and dumps the input (str, bytes, bytearray, dict) to json. Accepts every kwarg of json.dumps.
await prettify('{"this": "is", "an_": "example", "here": 123, "even": 1.02, "but": False}')
await prettify(b"{\"X\": 123}")
await prettify(bytearray("{\"X\": 123}", encoding='utf-8'))
#or use the decorator
@jpretty(silent=True)
async def async_json():
#return a json-like str, bytes, bytearray, dict and the decorator will convert it
return "{\"instead\": \"here\", \"is\": \"async\"}"
Other Utilities
to_bytes: converts input (str, bytes, bytearray, dict) to io.BytesIO
await to_bytesio('{"this": "is", "an_": "example", "here": 123, "even": 1.02, "but": False}')
#or use the decorator
@jbytesio()
async def json_to_bytesio():
#return a json-like str, bytes, bytearray, dict and the decorator will convert it
return '{"in": "this", "example": "the", "json": "function", "is": "sync"}'
Notes
You can use the boolean kwarg silent for skipping encoding exceptions.
For custom encoder use the kwarg encoder instead of cls in the function that uses the custom encoder.
You can decorate both sync and async functions but always return async function that needs to be awaited.
Metadata
Release files for apjson 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| apjson-0.0.3.tar.gz | 5.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| apjson-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.8 kB
Release files / apjson-0.0.3.tar.gz
| Download URL | apjson-0.0.3.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
86b68cc6e6a7e5632342679e1173702224f40cddf0a93ab6dbfd89f0be7e1f09
|
|
BLAKE2b-256 checksum How to use checksums |
daf184f33ec31bfdca4b77bd0254f235c892f37b29d4b67f9d7a96381b8fe77c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.2
|
Release files / apjson-0.0.3-py3-none-any.whl
| Download URL | apjson-0.0.3-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f127f55f7788fa3c413bf5a58b8bd1f097661708547cabdc9ed1fe51f0308c04
|
|
BLAKE2b-256 checksum How to use checksums |
27e40859cf97e1363d417dca5d2529acc42e7b953b491d64b0788119e3cbcbe8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.2
|
Security for apjson 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.