Skip to main content

Custom Datetime JSON Serializer

Project description

CDJS (Custom Datetime JSON Serializer)

cdjs is an extension for orjson to serialize datetime in a 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.

Example

import datetime
import orjson
from cdjs import serialize_date

mydate = datetime.datetime(2021, 1, 1, hour=0, minute=4, second=36, microsecond=123000)
orjson.dumps(mydate, option=orjson.OPT_PASSTHROUGH_DATETIME, default=serialize_date)

Benchmarks

TODO

Installation

pip install cdjs

Building

To make a develop build

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 Version Support

  • python 3.6

Project details


Download files

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

Source Distribution

cdjs-0.1.3.tar.gz (9.0 kB view hashes)

Uploaded Source

Built Distribution

cdjs-0.1.3-cp36-cp36m-manylinux2010_x86_64.whl (144.2 kB view hashes)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page