SQLAlchemy type to store aware datetime values
Project description
SQLAlchemy-Utc
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.14.0
Released on September 24, 2021.
Add cache_ok flag on UtcDateTime to supress Pandas warnings. [#14 by derekderie]
0.13.0
Released on September 24, 2021.
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.
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
Built Distribution
Hashes for SQLAlchemy_Utc-0.14.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2379eed5cce372128b5e744ce382decd262b2c742ab31f7f22ca11c6647f60b |
|
MD5 | 0d0fef7ff6cc8ad94be3b85d4d421b82 |
|
BLAKE2b-256 | e789ccfe4b579784f852c64f0fcb127e560990c2d75a2514dda51a9c87fb3782 |