bson_timezone
A package that provides timezone support for MongoDB bson -> https://api.mongodb.com/python/current/api/bson/index.html
MongoDB bson is great - but it doens't allow for timezone support. This package rectifies that.
This package provides a new dumps and loads method that overrides the ~bson.json_util.dumps and ~bson.json_util.load functions
in a few key places to support timezones - everything else works in the same way as in the core package.
Installation
pip install bson_timezone
Usage
bson_timezone handle timezone aware and timezone naive datetimes.
bson_timezone retains all existing functionality of ~bson.json_util.dumps - meaning you can provide json_options to configure the output
as required.
Dumping a timezone aware datetime
>>> from datetime import datetime
>>> from bson_timezone import bson_tz_dumps
>>> import pytz
>>> timezone = pytz.timezone("America/New_York")
>>> dt = datetime(2020,6,20,12,30,45).astimezone(timezone)
>>> bson_tz_dumps(dt)
'{"$date": 1592652645000, "$zone": "America/New_York", "$offset": {"total_seconds": -14400.0}}'
Loading a timezone aware datetime
>>> from datetime import datetime
>>> from bson_timezone import bson_tz_loads
>>> dumped_data = '{"$date": 1592652645000, "$zone": "America/New_York", "$offset": {"total_seconds": -14400.0}}'
>>> bson_tz_loads(dumped_data)
datetime.datetime(2020, 6, 20, 7, 30, 45, tzinfo=<DstTzInfo 'America/New_York' EDT-1 day, 20:00:00 DST>)
Dumping a timezone naive datetime
>>> from datetime import datetime
>>> from bson_timezone import bson_tz_dumps
>>> dt = datetime(2020,6,20,12,30,45)
>>> bson_tz_dumps(dt)
'{"$date": 1592656245000, "$zone": null, "$offset": null}'
Loading a timezone naive datetime
>>> from datetime import datetime
>>> from bson_timezone import bson_tz_loads
>>> dumped_data = '{"$date": 1592656245000, "$zone": null, "$offset": null}'
>>> bson_tz_loads(dumped_data)
datetime.datetime(2020, 6, 20, 7, 30, 45)
Running the tests
python setup.py test
Metadata
Release files for bson-timezone 0.0.2
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 | |
|---|---|---|---|---|
| bson_timezone-0.0.2.tar.gz | 5.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bson_timezone-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.9 kB
Release files / bson_timezone-0.0.2.tar.gz
| Download URL | bson_timezone-0.0.2.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
74fb915cf6f6575a4424fb61b51c5d28368c91bc8c10a18f250d38186705ef50
|
|
BLAKE2b-256 checksum How to use checksums |
f9ce8feb6191b86e6198495a530a5c928cc4fc4027e0d9f7c61d8a3325e4f41d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.5
|
Release files / bson_timezone-0.0.2-py3-none-any.whl
| Download URL | bson_timezone-0.0.2-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8ece6080a474ecba9cd37d92f6d7ee5caa6344cc3c99095c9536399d92b55025
|
|
BLAKE2b-256 checksum How to use checksums |
76fe990d809371cdacf2780def0dce8f647d87920917a8061c1a265c2b702fef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.5
|
Security for bson-timezone 0.0.2
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.