Skip to main content

Add dunder-methods to SQLAlchemy models with attrs

Project description

CI status

Use attrs to add __repr__, __eq__, __cmp__, and __hash__ methods according to the fields on a SQLAlchemy model class.

from attrs_sqlalchemy import attrs_sqlalchemy

@attrs_sqlalchemy
class MyModel(Base):
    __tablename__ = 'mymodel'

    id = sa.Column(Integer, primary_key=True)
    text = sa.Column(sa.String)

instance = MyModel(id=1, text='hello')
same_data = MyModel(id=1, text='hello')
same_pk = MyModel(id=1, text='world')

assert instance == same_data
assert instance != same_pk
assert repr(instance) == "MyModel(id=1, text='hello')"

Project details


Download files

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

Source Distribution

attrs_sqlalchemy-0.1.0.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

attrs_sqlalchemy-0.1.0-py2.py3-none-any.whl (5.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file attrs_sqlalchemy-0.1.0.tar.gz.

File metadata

File hashes

Hashes for attrs_sqlalchemy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3cd34358b49551007e4c2b253c1c4e65c1c0d7be2a9216ca8be9a72873988d65
MD5 19fb0de2c223119db13c7ba9b9f2b197
BLAKE2b-256 3d0d7011942d531e2a6b16e003190e4427f436177600f92781349c25d598086d

See more details on using hashes here.

File details

Details for the file attrs_sqlalchemy-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for attrs_sqlalchemy-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5d39b4f5e5fed12f5aa9da0fc7220fc9a49b4b242ab6ce70c6b2923fb5170956
MD5 4a5ed525ca833ed06713426a13c435cb
BLAKE2b-256 336b0887c62a8ec6b57e07ea0283c0ac58d272e5f16b3ad9327ecb897b975942

See more details on using hashes here.

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