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')"

Download files

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

Files for attrs-sqlalchemy, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size attrs_sqlalchemy-0.1.0-py2.py3-none-any.whl (5.1 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size attrs_sqlalchemy-0.1.0.tar.gz (3.0 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page