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.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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for SQLAlchemy-Utc, version 0.10.0
Filename, size File type Python version Upload date Hashes
Filename, size SQLAlchemy_Utc-0.10.0-py2.py3-none-any.whl (6.6 kB) File type Wheel Python version 3.6 Upload date Hashes View hashes
Filename, size SQLAlchemy-Utc-0.10.0.tar.gz (3.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page