{"library":"sqlalchemy-repr","title":"SQLAlchemy Repr","type":"library","description":"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.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install sqlalchemy-repr"],"cli":null},"imports":["from sqlalchemy_repr import ReprMixin"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/manicmaniac/sqlalchemy-repr","docs":null,"changelog":null,"pypi":"https://pypi.org/project/sqlalchemy-repr/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"from sqlalchemy import create_engine, Column, Integer, String\nfrom sqlalchemy.orm import sessionmaker\nfrom sqlalchemy.ext.declarative import declarative_base\nfrom sqlalchemy_repr import ReprMixin\n\n# 1. Setup SQLAlchemy Base\nBase = declarative_base()\n\n# 2. Define a model with ReprMixin\nclass User(ReprMixin, Base):\n    __tablename__ = 'users'\n    id = Column(Integer, primary_key=True)\n    name = Column(String)\n    email = Column(String)\n\n    # Optional: Customize which attributes are shown in repr\n    _repr_values = ['id', 'name']\n\n# 3. Create an engine and tables\nengine = create_engine('sqlite:///:memory:')\nBase.metadata.create_all(engine)\n\n# 4. Create a session\nSession = sessionmaker(bind=engine)\nsession = Session()\n\n# 5. Create and add an instance\nuser1 = User(id=1, name='Alice', email='alice@example.com')\nuser2 = User(id=2, name='Bob', email='bob@example.com')\nsession.add_all([user1, user2])\nsession.commit()\n\n# 6. Demonstrate the custom repr\nretrieved_user = session.query(User).filter_by(name='Alice').first()\nprint(f\"User instance repr: {retrieved_user}\")\n# Expected output (approx): User(id=1, name='Alice')\n\n# Clean up\nsession.close()","lang":"python","description":"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`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}