Skip to main content

Backport of the standard library zoneinfo module

Project description

backports.zoneinfo: Backport of the standard library module zoneinfo

This package was originally the reference implementation for PEP 615, which proposes support for the IANA time zone database in the standard library, and now serves as a backport to Python 3.7+.

This exposes the backports.zoneinfo module, which is a backport of the zoneinfo module. The backport's documentation can be found on readthedocs.

The module uses the system time zone data if available, and falls back to the tzdata package (available on PyPI) if installed.

Installation and depending on this library

This module is called backports.zoneinfo on PyPI. To install it in your local environment, use:

pip install backports.zoneinfo

Or (particularly on Windows), you can also use the tzdata extra (which basically just declares a dependency on tzdata, so this doesn't actually save you any typing 😅):

pip install backports.zoneinfo[tzdata]

If you want to use this in your application, it is best to use PEP 508 environment markers to declare a dependency conditional on the Python version:

backports.zoneinfo;python_version<"3.9"

Support for backports.zoneinfo in Python 3.9+ is currently minimal, since it is expected that you would use the standard library zoneinfo module instead.

Use

The backports.zoneinfo module should be a drop-in replacement for the Python 3.9 standard library module zoneinfo. If you do not support anything earlier than Python 3.9, you do not need this library; if you are supporting Python 3.7+, you may want to use this idiom to "fall back" to backports.zoneinfo:

try:
    import zoneinfo
except ImportError:
    from backports import zoneinfo

To get access to time zones with this module, construct a ZoneInfo object and attach it to your datetime:

>>> from backports.zoneinfo import ZoneInfo
>>> from datetime import datetime, timedelta, timezone
>>> dt = datetime(1992, 3, 1, tzinfo=ZoneInfo("Europe/Minsk"))
>>> print(dt)
1992-03-01 00:00:00+02:00
>>> print(dt.utcoffset())
2:00:00
>>> print(dt.tzname())
EET

Arithmetic works as expected without the need for a "normalization" step:

>>> dt += timedelta(days=90)
>>> print(dt)
1992-05-30 00:00:00+03:00
>>> dt.utcoffset()
datetime.timedelta(seconds=10800)
>>> dt.tzname()
'EEST'

Ambiguous and imaginary times are handled using the fold attribute added in PEP 495:

>>> dt = datetime(2020, 11, 1, 1, tzinfo=ZoneInfo("America/Chicago"))
>>> print(dt)
2020-11-01 01:00:00-05:00
>>> print(dt.replace(fold=1))
2020-11-01 01:00:00-06:00

>>> UTC = timezone.utc
>>> print(dt.astimezone(UTC))
2020-11-01 06:00:00+00:00
>>> print(dt.replace(fold=1).astimezone(UTC))
2020-11-01 07:00:00+00:00

Contributing

Currently we are not accepting contributions to this repository because we have not put the CLA in place and we would like to avoid complicating the process of adoption into the standard library. Contributions to CPython will eventually be backported to this repository — see the Python developer's guide for more information on how to contribute to CPython.

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

backports.zoneinfo-0.1.0b1.tar.gz (72.1 kB view details)

Uploaded Source

Built Distributions

backports.zoneinfo-0.1.0b1-cp38-cp38-win_amd64.whl (38.6 kB view details)

Uploaded CPython 3.8 Windows x86-64

backports.zoneinfo-0.1.0b1-cp38-cp38-win32.whl (36.5 kB view details)

Uploaded CPython 3.8 Windows x86

backports.zoneinfo-0.1.0b1-cp38-cp38-macosx_10_14_x86_64.whl (35.6 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

backports.zoneinfo-0.1.0b1-cp37-cp37m-win_amd64.whl (38.4 kB view details)

Uploaded CPython 3.7m Windows x86-64

backports.zoneinfo-0.1.0b1-cp37-cp37m-win32.whl (36.2 kB view details)

Uploaded CPython 3.7m Windows x86

backports.zoneinfo-0.1.0b1-cp37-cp37m-macosx_10_14_x86_64.whl (35.4 kB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

File details

Details for the file backports.zoneinfo-0.1.0b1.tar.gz.

File metadata

  • Download URL: backports.zoneinfo-0.1.0b1.tar.gz
  • Upload date:
  • Size: 72.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for backports.zoneinfo-0.1.0b1.tar.gz
Algorithm Hash digest
SHA256 aca81b6bca379f5764c117598ac11d894f7ca1977749375e178763bbbb30e765
MD5 d868950baaa810f8f37344df594a237e
BLAKE2b-256 522d4c6a9436cb38c1812bf1d75afb4d395ffbb3fbfba9cd8898704dc88b7e39

See more details on using hashes here.

File details

Details for the file backports.zoneinfo-0.1.0b1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: backports.zoneinfo-0.1.0b1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 38.6 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for backports.zoneinfo-0.1.0b1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 6484e89e3894c4c1ab76a667f90da6816f3efeedd5961ef6b7242c486b52d89b
MD5 4aa66a9dbba7435c5f5afb6d8b8cd6d4
BLAKE2b-256 f372227d9361261c06a6919ea0749d0dc4eb72a6c73099db65b82e960ff07cfd

See more details on using hashes here.

File details

Details for the file backports.zoneinfo-0.1.0b1-cp38-cp38-win32.whl.

File metadata

  • Download URL: backports.zoneinfo-0.1.0b1-cp38-cp38-win32.whl
  • Upload date:
  • Size: 36.5 kB
  • Tags: CPython 3.8, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for backports.zoneinfo-0.1.0b1-cp38-cp38-win32.whl
Algorithm Hash digest
SHA256 8e0080b792a2ab274823ecb868662f67b056a0fcf606b26fce5c6f5da4e1cc0c
MD5 7926081471f2a17e6ad2cc9ef771b36d
BLAKE2b-256 f5234927c4343c7fe5b99391c5f307601dc53ceff2b7b810874ec397ce6a6ef4

See more details on using hashes here.

File details

Details for the file backports.zoneinfo-0.1.0b1-cp38-cp38-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for backports.zoneinfo-0.1.0b1-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 3c41f4b5ec304bbcdd3bf7b731ec1fbb07ddf78a50262576f46ec77f00027fde
MD5 3c3428747f1a325d06de1ff716ff9746
BLAKE2b-256 f9eb229a990345477aa042065c73663c108e293353f8b9d94c941dbed36241de

See more details on using hashes here.

File details

Details for the file backports.zoneinfo-0.1.0b1-cp38-cp38-manylinux1_i686.whl.

File metadata

  • Download URL: backports.zoneinfo-0.1.0b1-cp38-cp38-manylinux1_i686.whl
  • Upload date:
  • Size: 71.6 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for backports.zoneinfo-0.1.0b1-cp38-cp38-manylinux1_i686.whl
Algorithm Hash digest
SHA256 97972ec8d7b509eb9d2d5c9ff005aebbe0e8c6a50ef4700a6498d79a9af65ba4
MD5 7c2887c6f11f55897bbc79b8f5e8874d
BLAKE2b-256 15aa99691fa459991fcb5f98ced2e0b2dcfca94f5011ebf295c86256cad0d328

See more details on using hashes here.

File details

Details for the file backports.zoneinfo-0.1.0b1-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: backports.zoneinfo-0.1.0b1-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 35.6 kB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for backports.zoneinfo-0.1.0b1-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 0d57ef70af693b7258ee63d409d0f452a4d07357643ebc9f728f68384cd4864b
MD5 841366755694d530a9a49d4f62309146
BLAKE2b-256 8ce733ed12e09448832f0929f2131435ea2577e31db3b1e5c65efa67fb3deec7

See more details on using hashes here.

File details

Details for the file backports.zoneinfo-0.1.0b1-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: backports.zoneinfo-0.1.0b1-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 38.4 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for backports.zoneinfo-0.1.0b1-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 32c3b8c5614c874bdd5b3ea5e0a35ad65bf8fc73420967bfe3c3fb76d4596db1
MD5 f2d16c42c5ab72a8217a655160b6bee0
BLAKE2b-256 f3e86011ee0c0274c681a50fe84e3ab7ba5e03915d000b3c09ec63fb217eb7b5

See more details on using hashes here.

File details

Details for the file backports.zoneinfo-0.1.0b1-cp37-cp37m-win32.whl.

File metadata

  • Download URL: backports.zoneinfo-0.1.0b1-cp37-cp37m-win32.whl
  • Upload date:
  • Size: 36.2 kB
  • Tags: CPython 3.7m, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for backports.zoneinfo-0.1.0b1-cp37-cp37m-win32.whl
Algorithm Hash digest
SHA256 5bbc89eade453c396cbe929e21a472768736529616b188694bd6ad83f3e3e5d4
MD5 e06ef305c73987508ec8ffb7465848dc
BLAKE2b-256 f008eab799f8b740cff6947c7d1268e38bb00b0a6ce0d0770d127e39284a725a

See more details on using hashes here.

File details

Details for the file backports.zoneinfo-0.1.0b1-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for backports.zoneinfo-0.1.0b1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 9124a2a8baab4e0267659bf2062fefbe3cce365d8324e77daaae6e2cb52c81dc
MD5 2a5e0d7557e1c731906e1eb95c14db88
BLAKE2b-256 4590e2bcf9161a297dacda20b3f21f5cbec715393fac38f918db10729adc7d3b

See more details on using hashes here.

File details

Details for the file backports.zoneinfo-0.1.0b1-cp37-cp37m-manylinux1_i686.whl.

File metadata

  • Download URL: backports.zoneinfo-0.1.0b1-cp37-cp37m-manylinux1_i686.whl
  • Upload date:
  • Size: 68.5 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for backports.zoneinfo-0.1.0b1-cp37-cp37m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 a4928d86336623d36d2dee60cbef8c5f5e2bd3542037096a858b6764d6703d62
MD5 30eefa65fce094622d3ee6528d636dec
BLAKE2b-256 a2e29aa2f461a2decd60d41041faa18d4cb140fd2b667e8573cf1fe839286b51

See more details on using hashes here.

File details

Details for the file backports.zoneinfo-0.1.0b1-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: backports.zoneinfo-0.1.0b1-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 35.4 kB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for backports.zoneinfo-0.1.0b1-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 793aa1635276e9b295ad0314ad02b8aed7cd1e233a94660c45c6de6f2fb099bb
MD5 bffbb67e8d1986731da3a533ea40cc73
BLAKE2b-256 b74f198b43f767c000c6cf678cea24f93581de16ae09aa380552c1952bf1ab8f

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