Skip to main content

SQLAlchemy-ModelID provides a base for SQLAlchemy models with a model_id property. This conveniently distinguishes between models with the same primary key but from different tables.

Installation

$ pip install sqlalchemy-modelid

Quickstart

from sqlalchemy_modelid import ModelIdBase

# standard session creation
from sqlalchemy import create_engine, Column, Integer
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, scoped_session

engine = create_engine('sqlite:///:memory:')
session_factory = sessionmaker(bind=engine)
Session = scoped_session(session_factory)
session = Session()
Base = declarative_base()

# subclass `ModelIdBase` to add a `model_id` property to any model
class Model(ModelIdBase, Base):
    __tablename__ = 'model'
    id = Column(Integer, primary_key=True)

# create the database
Base.metadata.create_all(engine)

# example
my_model = Model()
session.add(my_model)
session.commit()
my_model.model_id

Out:

model-1

Citation

@software{bowen2020sqlalchemy-modelid,
  author = {Dillon Bowen},
  title = {SQLAlchemy-ModelID},
  url = {https://dsbowen.github.io/sqlalchemy-modelid/},
  date = {2020-06-05},
}

License

Users must cite this package in any publications which use it.

It is licensed with the MIT License.

Metadata

Release files for sqlalchemy-modelid 0.0.3

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

Source distribution (sdist)

Source distribution for sqlalchemy-modelid 0.0.3
File Size Uploaded
sqlalchemy-modelid-0.0.3.tar.gz 2.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlalchemy-modelid 0.0.3
File Interpreter ABI Platform
sqlalchemy_modelid-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 5.4 kB

Release files / sqlalchemy-modelid-0.0.3.tar.gz

Download URL sqlalchemy-modelid-0.0.3.tar.gz
Size 2.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c4f11aa323ef34b3a8a84e5f13e89dc84706b12a62c2d063bd5eb438c3c367ce
BLAKE2b-256 checksum
How to use checksums
05ada076ece0f7b0eb612e52e99993094524617b1629118ff6c1a6d375b164ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.8

Release files / sqlalchemy_modelid-0.0.3-py3-none-any.whl

Download URL sqlalchemy_modelid-0.0.3-py3-none-any.whl
Size 3.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc21a9e5d8e716ace24c883775e2061f74ce900c6a8201de1ce4b2094028532f
BLAKE2b-256 checksum
How to use checksums
8b4cfb2da475c1c8954fecb1675d1f67658e8485567808a1f99df2a71fb16795
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.3.1 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.8

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

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