Skip to main content

JSON with tz-aware datetime support

Project description

Sick of rewriting the same JSON datetime handling code for each project? jsondate3-aware is a drop-in replacement for Python’s standard json library that adds sensible handling of datetime and date objects.

jsondate3-aware uses ISO8601 for encoding datetime objects and the date-specific part of ISO6801 for encoding date objects.

It:

  • supports Python 2 and 3

  • creates timezone-aware datetime objects when able

  • supports JavaScript-style dates (datetime.datetime(%Y, %m, %d, %H, %M, %S))

Example:

import datetime
import jsondate3 as json

>>> data = json.dumps(dict(created_at=datetime.datetime(2012, 10, 31)))
'{"created_at": "2012-10-31T00:00:00Z"}'

>>> json.loads(data)
{u'created_at': datetime.datetime(2012, 10, 31, 0, 0, tzinfo=datetime.timezone.utc)}

>>> date = json.dumps(dict(date=datetime.date(2012, 10, 31)))
'{"date": "2012-10-31"}'

>>> json.loads(data)
{u'created_at': datetime.date(2012, 10, 31)}

Testing

Run them with:

python -m unittest tests.test_jsondate

Deployment

If you wish to create a new version manually, the process is:

  1. Update version info in setup.py

  2. Install the requirements in requirements_dev.txt

  3. Set up a config file at ~/.pypirc

  4. Generate a universal distribution that worksin py2 and py3 (see setup.cfg)

    rm -r dist &&  python setup.py sdist bdist_wheel
  5. Upload the distributions

    twine upload dist/* -r pypi (or pypitest)

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

jsondate3-aware-0.2.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

jsondate3_aware-0.2.0-py2.py3-none-any.whl (5.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file jsondate3-aware-0.2.0.tar.gz.

File metadata

  • Download URL: jsondate3-aware-0.2.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.1.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/2.7.18rc1

File hashes

Hashes for jsondate3-aware-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d24359eb9e638a86be6c307663ba39510fc4221c2900c6ab31d14df0a8585b83
MD5 cc5897a30c96edefff66ed16e90da731
BLAKE2b-256 b364ce36e68fb4e1f67fdd0b1faeb8ec0499693b43d4bdaef94e8936ff6409aa

See more details on using hashes here.

File details

Details for the file jsondate3_aware-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: jsondate3_aware-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.1.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/2.7.18rc1

File hashes

Hashes for jsondate3_aware-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 295c96e4a71cac99dc731c5c5c8594f4dc10dfdffb73db7bc918cee745cd8ada
MD5 51ccbc1af72bc18a2cd321c20a643a74
BLAKE2b-256 e023385283f5337802f452ab91b15ae41490fa30bb9c025573f55c9734a0256d

See more details on using hashes here.

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