SQLAlchemy column types for the whenever datetime library
Project description
whenever-sqlalchemy
SQLAlchemy column types for the whenever datetime library.
Installation
pip install whenever-sqlalchemy
Type mapping
| whenever type | SQL type |
|---|---|
Instant |
TIMESTAMP WITH TIME ZONE |
PlainDateTime |
TIMESTAMP (no timezone) |
Date |
DATE |
Time |
TIME |
Usage
SQLAlchemy 2.x — Mapped[] style (recommended)
Register type_annotation_map on your DeclarativeBase once, then use
Mapped[Instant] exactly like you would use Mapped[datetime]:
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
from whenever import Date, Instant, PlainDateTime, Time
from whenever_sqlalchemy import type_annotation_map
class Base(DeclarativeBase):
type_annotation_map = type_annotation_map # merge with your own if needed
class Event(Base):
__tablename__ = "events"
id: Mapped[int] = mapped_column(primary_key=True)
timestamp: Mapped[Instant]
scheduled: Mapped[PlainDateTime | None]
date: Mapped[Date | None]
time: Mapped[Time | None]
SQLAlchemy 1.4 / 2.x — Column() style
from sqlalchemy import Column, Integer
from whenever_sqlalchemy import DateType, InstantType, PlainDateTimeType, TimeType
class Event(Base):
__tablename__ = "events"
id = Column(Integer, primary_key=True)
timestamp = Column(InstantType)
scheduled = Column(PlainDateTimeType, nullable=True)
date = Column(DateType, nullable=True)
time = Column(TimeType, nullable=True)
Notes
Nanoseconds — whenever types support nanosecond precision; SQL
TIMESTAMP columns store at most microsecond precision. Values are
truncated (not rounded) to microseconds on write, matching to_stdlib().
server_default — server_default=func.now() works as expected: the
server sets the value and SQLAlchemy fetches it back, converting it to the
appropriate whenever type.
Dialect notes
- PostgreSQL: uses
TIMESTAMPTZnatively; full roundtrip fidelity. - SQLite: stores datetimes as text and drops timezone info.
InstantTypereattaches UTC tzinfo on retrieval (the stored value is UTC). - MySQL / MariaDB / SQL Server: similar to SQLite for timezone columns; the UTC-reattach workaround covers these too.
Compatibility
- Python 3.10+
- whenever 0.10+
- SQLAlchemy 1.4+ (
Column()style); SQLAlchemy 2.0+ (Mapped[]style)
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file whenever_sqlalchemy-0.1.0b2.tar.gz.
File metadata
- Download URL: whenever_sqlalchemy-0.1.0b2.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f69b8f8235c41abab24f2d2dd38f9139aa3ccc94b98e5b18a4e919bd1f3acde3
|
|
| MD5 |
08f83371cfcd1bda6dea8fbffad81734
|
|
| BLAKE2b-256 |
ac06df4dc0f35f7b751d329891a5d85b69628aa8642ae5df985aeb23568fdee5
|
Provenance
The following attestation bundles were made for whenever_sqlalchemy-0.1.0b2.tar.gz:
Publisher:
publish.yml on ariebovenberg/whenever-sqlalchemy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
whenever_sqlalchemy-0.1.0b2.tar.gz -
Subject digest:
f69b8f8235c41abab24f2d2dd38f9139aa3ccc94b98e5b18a4e919bd1f3acde3 - Sigstore transparency entry: 1218854756
- Sigstore integration time:
-
Permalink:
ariebovenberg/whenever-sqlalchemy@d4f26c4405890b9a818429c9d77239030d2645dc -
Branch / Tag:
refs/tags/v0.1.0b2 - Owner: https://github.com/ariebovenberg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d4f26c4405890b9a818429c9d77239030d2645dc -
Trigger Event:
push
-
Statement type:
File details
Details for the file whenever_sqlalchemy-0.1.0b2-py3-none-any.whl.
File metadata
- Download URL: whenever_sqlalchemy-0.1.0b2-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32afd6c13dc03280dede903edc7e1806475ff715fd2446100846eda22749214e
|
|
| MD5 |
b1e18b575992e8cc88750096d7f1baad
|
|
| BLAKE2b-256 |
826b16427d0f55be0730215c68075cdb1d204b14b6606149a2407f6d7e42546c
|
Provenance
The following attestation bundles were made for whenever_sqlalchemy-0.1.0b2-py3-none-any.whl:
Publisher:
publish.yml on ariebovenberg/whenever-sqlalchemy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
whenever_sqlalchemy-0.1.0b2-py3-none-any.whl -
Subject digest:
32afd6c13dc03280dede903edc7e1806475ff715fd2446100846eda22749214e - Sigstore transparency entry: 1218854809
- Sigstore integration time:
-
Permalink:
ariebovenberg/whenever-sqlalchemy@d4f26c4405890b9a818429c9d77239030d2645dc -
Branch / Tag:
refs/tags/v0.1.0b2 - Owner: https://github.com/ariebovenberg
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d4f26c4405890b9a818429c9d77239030d2645dc -
Trigger Event:
push
-
Statement type: