{"id":17289546,"url":"https://github.com/amolenaar/roles","last_synced_at":"2025-05-12T18:46:56.763Z","repository":{"id":627959,"uuid":"268470","full_name":"amolenaar/roles","owner":"amolenaar","description":"Library for Role based development","archived":false,"fork":false,"pushed_at":"2024-08-27T19:55:23.000Z","size":315,"stargazers_count":57,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-21T14:53:25.415Z","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":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amolenaar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2009-08-04T07:09:46.000Z","updated_at":"2024-08-27T19:55:26.000Z","dependencies_parsed_at":"2024-01-16T15:34:13.374Z","dependency_job_id":"5913ee4f-071c-44ab-9552-2a3d7e336a02","html_url":"https://github.com/amolenaar/roles","commit_stats":{"total_commits":142,"total_committers":2,"mean_commits":71.0,"dds":0.007042253521126751,"last_synced_commit":"b24b8f2f6af55b280e834f18354aacd88fe7c073"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amolenaar%2Froles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amolenaar%2Froles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amolenaar%2Froles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amolenaar%2Froles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amolenaar","download_url":"https://codeload.github.com/amolenaar/roles/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253802184,"owners_count":21966761,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":"2024-10-15T10:35:07.927Z","updated_at":"2025-05-12T18:46:56.359Z","avatar_url":"https://github.com/amolenaar.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Roles\n\nLibrary for Role based development.\n\nPythonic implementation of the DCI (Data Context Interaction) pattern\n(http://www.artima.com/articles/dci_vision.html).\n\nThe big difference with mixins is that this role is applied only to the subject\ninstance, not to the subject class (alas, a new class is constructed).\n\nRoles can be assigned and revoked. Multiple roles can be applied to an\ninstance. Revocation can happen in any particular order.\n\nHomepage: http://github.com/amolenaar/roles\n\nReleases: http://pypi.python.org/pypi/roles\n\n\n## Using Roles\n\nAs a basic example, consider a domain class:\n\n```python\n\u003e\u003e\u003e class Person:\n...     def __init__(self, name):\n...         self.name = name\n\u003e\u003e\u003e person = Person(\"John\")\n```\n\nThe instance should participate in a collaboration in which it fulfills a\nparticular role:\n\n```python\n\u003e\u003e\u003e from roles import RoleType\n\u003e\u003e\u003e class Carpenter(metaclass=RoleType):\n...     def chop(self):\n...          return \"chop, chop\"\n\n```\nAssign the role to the person:\n\n```python\n\u003e\u003e\u003e Carpenter(person)\t\t\t\t# doctest: +ELLIPSIS\n\u003c__main__.Person+Carpenter object at 0x...\u003e\n\u003e\u003e\u003e person\t\t\t\t\t# doctest: +ELLIPSIS\n\u003c__main__.Person+Carpenter object at 0x...\u003e\n\n```\n\nThe person is still a Person:\n\n```python\n\u003e\u003e\u003e isinstance(person, Person)\nTrue\n\n```\n... and can do carpenter things:\n\n```python\n\u003e\u003e\u003e person.chop()\n'chop, chop'\n\n```\n\nSee [`roles.py`](http://github.com/amolenaar/roles/blob/master/roles.py) for more examples.\n\n## Context\n\nRoles make a lot of sense when used in a context. A classic example is the\nmoney transfer example. Here two accounts are used and an amount of money is\ntransfered from one account to the other. So, one account playes the role of\nsource account and the other plays the role of target account.\n\nAn example can be found in [`example.py`](http://github.com/amolenaar/roles/blob/master/example.py).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famolenaar%2Froles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famolenaar%2Froles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famolenaar%2Froles/lists"}