Skip to main content

Convert to/from timezone aware datetimes when storing in a DBMS

Project description

Installation

pip install sqlalchemy-utcdatetime

Sample Usage

import sqlalchemy as sa
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_utcdatetime import UTCDateTime
import datetime, pytz

Base = declarative_base()

class MyModel(Base):
    __tablename__ = 'my_model'

    id = sa.Column(sa.Integer(), primary_key=True)
    my_datetime = sa.Column(UTCDateTime())


m = MyModel()
m.my_datetime = datetime.datetime.now(pytz.timezone('Australia/Sydney'))

Project details


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