{"id":37073412,"url":"https://github.com/thruflo/pyramid_alchemy","last_synced_at":"2026-01-14T08:37:01.770Z","repository":{"id":15216737,"uuid":"17945247","full_name":"thruflo/pyramid_alchemy","owner":"thruflo","description":"Pyramid framework integration to extend SQLAlchemy ORM classes with testable code.","archived":false,"fork":false,"pushed_at":"2014-03-20T14:48:59.000Z","size":120,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-01T01:23:23.500Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thruflo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-20T14:18:19.000Z","updated_at":"2014-03-20T14:48:59.000Z","dependencies_parsed_at":"2022-08-25T11:00:24.083Z","dependency_job_id":null,"html_url":"https://github.com/thruflo/pyramid_alchemy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/thruflo/pyramid_alchemy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thruflo%2Fpyramid_alchemy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thruflo%2Fpyramid_alchemy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thruflo%2Fpyramid_alchemy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thruflo%2Fpyramid_alchemy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thruflo","download_url":"https://codeload.github.com/thruflo/pyramid_alchemy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thruflo%2Fpyramid_alchemy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28414667,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T08:31:27.429Z","status":"ssl_error","status_checked_at":"2026-01-14T08:31:19.098Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-14T08:37:01.200Z","updated_at":"2026-01-14T08:37:01.761Z","avatar_url":"https://github.com/thruflo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Good frameworks, like [Pyramid][] and [Angular][], help developers write\ntestable code. [SQLAlchemy][] is a great framework. However, the sheer\nconvenience of having model instances returned from a database query\nencourages developers to write large ORM classes which can be hard to test.\n\nOne way to avoid this is to keep model classes [thin][] and write separate code\nto instantiate and manipulate them. The downside of this approach is the loss in\nconvenience: the separated, easily testable code isn't provided by default as\nan attribute of the model instances returned from a database query.\n\n[pyramid_alchemy][] provides an `add_model_method` Pyramid\n[configuration directive]() that extends [SQLAlchemy ORM][] classes in the same\nway that `add_request_method` [extends the Pyramid Request][]. Using this\ndirective allows developers to write easily testable code that is conveniently\navailable as a model instance attribute. For example, if you [include][] this\nin your Pyramid application:\n\n```python\nfrom .model import Spam\n\ndef get_eggs(instance, source='hens', limit=9, offset=0):\n    \"\"\"Example ORM instance method, implemented as a standalone function.\"\"\"\n    \n    query = instance.query.filter_by(source=source)\n    return query.offset(offset).limit(limit)\n\ndef includeme(config):\n    config.add_model_method(Spam, get_eggs, 'get_eggs')\n```\n\nYou can then use the `get_eggs` method from `Spam` instances:\n\n```python\nspam = Session.query(Spam).get(1)\neggs = spam.get_eggs()\n```\n\n### Interfaces\n\nJust as you can hang a Pyramid view off any context object implementing a\nspecific interface, you can extend any model instance implementing an interface.\nFor example, if your model looked something like this:\n\n```python\nfrom sqlalchemy.ext.declarative import declarative_base\nfrom zope.interfaces import implementer\n\nfrom .interfaces import IFilling\n\nBase = declarative_base()\n\n@implementer(IFilling)\nclass Ham(Base):\n    # ...\n\n@implementer(IFilling)\nclass Spam(Base):\n    # ...\n```\n\nThen you could extend all fillings -- current and future -- with:\n\n```python\nconfig.add_model_method(IFilling, get_eggs, 'get_eggs')\n```\n\n### Limitations\n\nNote that it's highly unlikely to be a good idea to use `add_model_method` to\nadd dynamic or hybrid methods that affect the underlying sql table or mapping.\n\n[Pyramid]: http://docs.pylonsproject.org/projects/pyramid/en/latest\n[Angular]: http://angularjs.org\n[SQLAlchemy]: http://docs.sqlalchemy.org/en/latest\n[pyramid_alchemy]: https://github.com/thruflo/pyramid_alchemy\n[configuration directive]: http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/extconfig.html\n[SQLAlchemy ORM]: http://docs.sqlalchemy.org/en/latest/orm\n[extends the Pyramid Request]: http://docs.pylonsproject.org/projects/pyramid/en/latest/api/config.html#pyramid.config.Configurator.add_request_method\n[include]: http://docs.pylonsproject.org/projects/pyramid/en/latest/api/config.html#pyramid.config.Configurator.include\n[thin]: http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthruflo%2Fpyramid_alchemy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthruflo%2Fpyramid_alchemy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthruflo%2Fpyramid_alchemy/lists"}