Skip to main content

This repo contains a custom column types for SQLAlchemy which I use in different projects.

The code should be compatible with SQLAlchemy 1.2.3 - 2.0 and Python 3.6 - 3.13 as well as pypy 3.9.

pip install ColumnAlchemy

UTCDateTime

UTCDateTime stores a Python tz-aware datetime.datetime value as UTC datetime in the database (without explicit timezone information). I use this to introduce tz-aware timezones in systems which expect "naive" datetimes in the database.

from schwarz.column_alchemy import UTCDateTime

class Foo(Base)
    __tablename__ = 'foo'
    id = Column(Integer, autoincrement=True, primary_key=True)
    timestamp = Column(UTCDateTime)

ShiftedDecimal

ShiftedDecimal stores a Decimal as integer in the database (with limited precision). This is especially useful to store decimal values even in sqlite which requires special treatment to store decimals.

from decimal import Decimal
from schwarz.column_alchemy import ShiftedDecimal

class Foo(Base)
    __tablename__ = 'foo'
    id = Column(Integer, autoincrement=True, primary_key=True)
    percentage = Column(ShiftedDecimal(4))

foo = Foo(percentage=Decimal('1.2324'))
# stores percentage as 12324 in the database but returns the
# correct Decimal value after loading.

ValuesEnum

TODO

IntValuesEnum

TODO

YearMonthColumn

YearMonth is similar to datetime.date but without a day attribute. It can be used to represent a calendar month and provides some convenience methods like first_date_of_month() and last_date_of_month(). A YearMonthColumn stores a YearMonth instance as "YYYY-MM" in the database.

from schwarz.column_alchemy import YearMonth, YearMonthColumn

class Foo(Base)
    __tablename__ = 'foo'
    id = Column(Integer, autoincrement=True, primary_key=True)
    month = Column(YearMonthColumn())

foo = Foo(month=YearMonth(2020, 7))
# stores "month" as "2020-07" in the database but returns a
# YearMonth instance after loading.

YearMonthIntColumn

Very similar to YearMonthColumn but stores YearMonth(2020, 7) as 202007 (integer).

Metadata

Release files for ColumnAlchemy 0.10.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for ColumnAlchemy 0.10.1
File Interpreter ABI Platform
ColumnAlchemy-0.10.1-py3-none-any.whl Python 3 none any Details

Release files / ColumnAlchemy-0.10.1-py3-none-any.whl

Download URL ColumnAlchemy-0.10.1-py3-none-any.whl
Size 27.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
68e46e215d92a401470a203b0a894bec7214a47def2ab1dddc1ed8f83f3929f9
BLAKE2b-256 checksum
How to use checksums
8a1e630cf9dc2b20b3e2403acd3fc1e207daa9c9f8662345c2946be35ba19c31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.1

Security for ColumnAlchemy 0.10.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page