CDJS (Custom Datetime JSON Serializer)
cdjs is an extension for orjson to serialize datetime (and other types) in a fast custom way.
By default orjson serializes datetime according to RFC 3339 format which sometimes may not suit.
orjson provides a mean to process datetime using custom serializer (via OPT_PASSTHROUGH_DATETIME flag and via default=custom_datetime_serializer).
Serializers implemented in Python are usually not fast enough, that's the reason behind implementation of the custom datetime serializer written in Rust to gain optimal speed.
Aside from datetimes, cdjs is an attempt to port bson.json_util.default() and to use with orjson as a default handler.
At the moment serialization of the following types are supported:
datetimebson.ObjectId
Example
import datetime
import hashlib
from bson import ObjectId
from cdjs import serialize
import orjson
mydata = {
'_id': ObjectId(hashlib.md5(b'test').hexdigest()[:24]),
'date': datetime.datetime(2021, 1, 1, hour=0, minute=4, second=36, microsecond=123000)
}
orjson.dumps(mydata, option=orjson.OPT_PASSTHROUGH_DATETIME, default=serialize)
# b'{"_id":{"$oid":"098f6bcd4621d373cade4e83"},"date":{"$date":"2021-01-01T00:04:36.123Z"}}'
Benchmarks
To run benchmark:
pip install -r bench-requirements.txt
python tests/benchmark.py --help
python tests/benchmark.py --scenario utc_dates
Installation
pip install cdjs
Building
To make a develop build
NOTE: Develop build doesn't enable optimizations, hence the result may work slow.
python ./setup.py develop
To make a release build
Pre-requisites
# switch to nightly channel
RUSTUP_USE_CURL=1 rustup default nightly-2021-01-31
pip install maturin
To compile, package and publish to PyPI
maturin build --no-sdist --release --strip --manylinux off
maturin publish
Testing
To run tests
python -m unittest -v tests.test_serialization
Python/OS Version Support
- Python 3.6 (tested)
- Python 3.7+ (not tested)
- Linux (with GLib 2.17+)
Metadata
Release files for cdjs 0.1.5
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 | Actions |
|---|---|---|---|---|
| cdjs-0.1.5.tar.gz | 41.7 kB | Without provenance | Details for cdjs-0.1.5.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cdjs-0.1.5-cp38-cp38-manylinux2010_x86_64.whl | CPython 3.8 | CPython 3.8 | Linux glibc 2.12+ x86-64 | Details for cdjs-0.1.5-cp38-cp38-manylinux2010_x86_64.whl |
| cdjs-0.1.5-cp36-cp36m-manylinux2010_x86_64.whl | CPython 3.6 | CPython 3.6 pymalloc | Linux glibc 2.12+ x86-64 | Details for cdjs-0.1.5-cp36-cp36m-manylinux2010_x86_64.whl |
Total release size: 334.1 kB
Release files / cdjs-0.1.5.tar.gz
| Download URL | cdjs-0.1.5.tar.gz |
|---|---|
| Size | 41.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
13804f563120aac2eb2dd05eae6f6eeff72b481142cd55f210dc3796e8211eba
|
|
BLAKE2b-256 checksum How to use checksums |
01089be7c897d0773d208736c7e8f0811216d885d8025358d22241d47e2eccfe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.9.4
|
Release files / cdjs-0.1.5-cp38-cp38-manylinux2010_x86_64.whl
| Download URL | cdjs-0.1.5-cp38-cp38-manylinux2010_x86_64.whl |
|---|---|
| Size | 146.2 kB |
| Tags | CPython 3.8 Linux glibc 2.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
d0d39ab3350b090628a69a3161cdcdef0a3fe6a17d59e4b196eb90f5527441ed
|
|
BLAKE2b-256 checksum How to use checksums |
9994952c73ff8018825e596a37aa8532936f5fc6cb58c6989275b4d716215a4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.9.4
|
Release files / cdjs-0.1.5-cp36-cp36m-manylinux2010_x86_64.whl
| Download URL | cdjs-0.1.5-cp36-cp36m-manylinux2010_x86_64.whl |
|---|---|
| Size | 146.1 kB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
4830b07e258d21a0b0473b500b8c08dd01b23194614bfe2b9584a0ff71523bd9
|
|
BLAKE2b-256 checksum How to use checksums |
cf8d44485c9073343aa1f3de9c414b5c1f005f9dfbb853f94ec5e9add463d470
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/0.9.4
|
Security for cdjs 0.1.5
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.