Skip to main content

Build Status Version Status Downloads

Versioning and auditing extension for SQLAlchemy.

Features

  • Creates versions for inserts, deletes and updates

  • Does not store updates which don’t change anything

  • Supports alembic migrations

  • Can revert objects data as well as all object relations at given transaction even if the object was deleted

  • Transactions can be queried afterwards using SQLAlchemy query syntax

  • Query for changed records at given transaction

  • Temporal relationship reflection. Version object’s relationship show the parent objects relationships as they where in that point in time.

  • Supports native versioning for PostgreSQL database (trigger based versioning)

QuickStart

pip install SQLAlchemy-Continuum

In order to make your models versioned you need two things:

  1. Call make_versioned() before your models are defined.

  2. Add __versioned__ to all models you wish to add versioning to

import sqlalchemy as sa
from sqlalchemy_continuum import make_versioned


make_versioned(user_cls=None)


class Article(Base):
    __versioned__ = {}
    __tablename__ = 'article'

    id = sa.Column(sa.Integer, primary_key=True, autoincrement=True)
    name = sa.Column(sa.Unicode(255))
    content = sa.Column(sa.UnicodeText)


article = Article(name='Some article', content='Some content')
session.add(article)
session.commit()

# article has now one version stored in database
article.versions[0].name
# 'Some article'

article.name = 'Updated name'
session.commit()

article.versions[1].name
# 'Updated name'


# lets revert back to first version
article.versions[0].revert()

article.name
# 'Some article'

For completeness, below is a working example.

from sqlalchemy_continuum import make_versioned
from sqlalchemy import Column, Integer, Unicode, UnicodeText, create_engine
from sqlalchemy.orm import Session, configure_mappers, declarative_base

make_versioned(user_cls=None)

Base = declarative_base()
class Article(Base):
    __versioned__ = {}
    __tablename__ = 'article'
    id = Column(Integer, primary_key=True, autoincrement=True)
    name = Column(Unicode(255))
    content = Column(UnicodeText)

configure_mappers()
engine = create_engine('sqlite://')
Base.metadata.create_all(engine)
session = Session(engine)

article = Article(name='Some article', content='Some content')
session.add(article)
session.commit()
article.versions[0].name
article.name = 'Updated name'
session.commit()
article.versions[1].name
article.versions[0].revert()
article.name

Resources

http://i.imgur.com/UFaRx.gif

More information

Download files

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

Source Distribution

sqlalchemy_continuum-1.7.0.tar.gz (95.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqlalchemy_continuum-1.7.0-py3-none-any.whl (54.0 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy_continuum-1.7.0.tar.gz.

File metadata

  • Download URL: sqlalchemy_continuum-1.7.0.tar.gz
  • Upload date:
  • Size: 95.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sqlalchemy_continuum-1.7.0.tar.gz
Algorithm Hash digest
SHA256 30efaa26a0c6325ac70d034847e6e972ae70616b6553bb016a27f7ed2f1a1003
MD5 0f9849d99fe97833b7c24169f4698d92
BLAKE2b-256 6ac810add9693dd2f2666ba3e8688e9163cb0f91a68704ac8d580e80a49c5135

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlalchemy_continuum-1.7.0.tar.gz:

Publisher: publish.yml on sqlalchemy-continuum/sqlalchemy-continuum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sqlalchemy_continuum-1.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlalchemy_continuum-1.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6bdce869bfc0b6f22b51ea3552669b68acfa05791a6349b29457cd1bab84dd7a
MD5 6adfb4817fd2d369f8d22c9a6a80b701
BLAKE2b-256 bdaf4f27754e52f8c23d5a0326b9b013f313243ed1bbf638be660dcd5daa4c41

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlalchemy_continuum-1.7.0-py3-none-any.whl:

Publisher: publish.yml on sqlalchemy-continuum/sqlalchemy-continuum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.7.0

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page