Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Add dunder-methods to SQLAlchemy models with attrs

Project Description

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

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

Release History

This version
History Node


Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(5.1 kB) Copy SHA256 Hash SHA256
Wheel py2.py3 Sep 27, 2016
(3.0 kB) Copy SHA256 Hash SHA256
Source None Sep 27, 2016

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers