sqlalchemy-repr, currently at version 0.1.0, is a lightweight Python library that automatically generates human-readable `__repr__` methods for SQLAlchemy declarative models. It aims to simplify debugging and logging by providing informative string representations of model instances without manual boilerplate. The project is stable but has a low release cadence.
pip install sqlalchemy-reprVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to integrate `ReprMixin` with a SQLAlchemy declarative model. By inheriting `ReprMixin` alongside `Base`, your model instances will automatically gain a sensible string representation. The example also shows how to customize the included attributes using `_repr_values`.
Monitor the project's GitHub repository for updates if using very new SQLAlchemy versions. Be prepared to implement custom `__repr__` methods or fork the library for compatibility if encountering issues with future SQLAlchemy releases.
Explicitly define the `_repr_values` attribute on your model to control which columns are included in the representation. For example: `_repr_values = ['id', 'username']` to exclude sensitive fields like `password_hash`.
When defining models with such relationships, consider carefully setting `_repr_values` to exclude relationship attributes. For very complex cases, implement a custom `__repr__` method to ensure controlled and efficient output.