Skip to main content

SQLAlchemy type to store aware datetime values

Project description

SQLAlchemy-Utc

https://badge.fury.io/py/SQLAlchemy-Utc.svg? https://travis-ci.org/spoqa/sqlalchemy-utc.svg?branch=master https://codecov.io/github/spoqa/sqlalchemy-utc/coverage.svg?branch=master

This package provides a drop-in replacement of SQLAlchemy’s built-in DateTime type with timezone=True option enabled. Although SQLAlchemy’s built-in DateTime type provides timezone=True option, since some vendors like SQLite and MySQL don’t provide timestamptz data type, the option doesn’t make any effect on these vendors.

UtcDateTime type is equivalent to the built-in DateTime with timezone=True option enabled on vendors that support timestamptz e.g. PostgreSQL, but on SQLite or MySQL, it shifts all datetime.datetime values to UTC offset before store them, and returns always aware datetime.datetime values through result sets.

Long story short, UtcDateTime does:

  • take only aware datetime.datetime,

  • return only aware datetime.datetime,

  • never take or return naive datetime.datetime,

  • ensure timestamps in database always to be encoded in UTC, and

  • work as you’d expect.

A SQLAlchemy helper function, utcnow(), is provided as an alternative to func.now() for generating UtcDateTime values on the server. For example: Column('time', UtcDateTime(), default=utcnow()).

Written by Hong Minhee at Spoqa, and distributed under MIT license.

Changelog

0.12.0

Released on May 7, 2021.

  • Add py.typed file to the package to be compatible with PEP-561. [#10 by Dima Boger]

0.11.0

Released on November 13, 2020.

  • Ensured always returning the datetime with UTC timezone. [#8 by Eduard Christian Dumitrescu]

0.10.0

Released on January 25, 2018.

  • Dropped support of older Python versions: 2.6, 3.2, and 3.3. [#2 by George Leslie-Waksman]

  • Added sqlalchemy_utc.utcnow() function as an alternative to sqlalchemy.sql.functions.now() for generating UtcDateTime values on the database server. [#4 by George Leslie-Waksman]

0.9.0

First version. Released on June 22, 2016.

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

SQLAlchemy-Utc-0.12.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

SQLAlchemy_Utc-0.12.0-py2.py3-none-any.whl (5.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file SQLAlchemy-Utc-0.12.0.tar.gz.

File metadata

  • Download URL: SQLAlchemy-Utc-0.12.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.4

File hashes

Hashes for SQLAlchemy-Utc-0.12.0.tar.gz
Algorithm Hash digest
SHA256 c21a7a95d02f04c04fdcdcc24a89a9ae3031737d934e558fb2efe6fe72af9666
MD5 7127742bb9be93a74ac645ba967b68cc
BLAKE2b-256 48c91b9158849e2a6ddb1186b5de40088f2c81f60bd79a66a1754c1f3406c65e

See more details on using hashes here.

File details

Details for the file SQLAlchemy_Utc-0.12.0-py2.py3-none-any.whl.

File metadata

  • Download URL: SQLAlchemy_Utc-0.12.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.4

File hashes

Hashes for SQLAlchemy_Utc-0.12.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1a30e52ee2e2e284e985bba3ecf28a998231ce754c7f97fff97a841a84bf1456
MD5 7690d3fb25fa306d79787f3284220a0c
BLAKE2b-256 b78da5bc5cd4fb453f38f9b7beb3aea111e3b4c8e96ce5db5c4bf8bbd74413db

See more details on using hashes here.

Supported by

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