Skip to main content

Datetime JSON

Github action badge PyPI version PyPI - License

Serialize and deserialize datetime objects to and from JSON.

This package provides:

  • 4 functions that wrap the corresponding functions of the json module:

    • load/loads - Deserialize a JSON string containing datetime objects
    • dump/dumps - Serialize python object containting datetime objects to JSON
  • two classes derived respectively from json.JSONEncoder and json.JSONDecoder:

    • DateTimeEncoder - Serialize a datetime object to JSON
    • DateTimeDecoder - Deserialize a JSON string to a datetime object

Installation

pip install datetimejson

Usage

Just replace json import by datetimejson in your code:

>>> from datetimejson import dumps, loads
>>> from datetime import datetime
>>> now = datetime.now()
>>> print(now)
2023-02-13 11:27:56.687439
>>> json_string = dumps(now)
>>> print(json_string)
{"__type__": "datetime", "year": 2023, "month": 2, "day": 13, "hour": 11, "minute": 27, "second": 56, "microsecond": 687439}
>>> print(loads(json_string))
2023-02-13 11:27:56.687439
>>> 

Original code by @ApptuitAI: https://gist.github.com/abhinav-upadhyay/5300137

Metadata

Release files for datetimejson 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for datetimejson 0.1.8
File Size Uploaded Provenance Actions
datetimejson-0.1.8.tar.gz 4.1 kB Without provenance Details for datetimejson-0.1.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for datetimejson 0.1.8
File Interpreter ABI Platform Actions
datetimejson-0.1.8-py3-none-any.whl Python 3 none any Details for datetimejson-0.1.8-py3-none-any.whl

Total release size: 7.8 kB

Release files / datetimejson-0.1.8.tar.gz

Download URL datetimejson-0.1.8.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
aeb6439e41459ad0692d246ecece747324a6b0afd63fa2e50c3fdebad64a2f1d
BLAKE2b-256 checksum
How to use checksums
0f807f8821d0bd3b340c5aa2ae276928bbbf5796c4baf12b48f0cd150173d06c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release files / datetimejson-0.1.8-py3-none-any.whl

Download URL datetimejson-0.1.8-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
01f36d3893e603357cd339169d520dde91654938c1bd21400e65e003dcfc37df
BLAKE2b-256 checksum
How to use checksums
4bc2f7f71e3a145507d752a4fd8799b790e62a02da4ef5efd91413052d5f2b93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Security for datetimejson 0.1.8

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page