{"id":37324742,"url":"https://github.com/rbroderi/protocol_implements_decorator","last_synced_at":"2026-01-16T03:27:20.903Z","repository":{"id":46328354,"uuid":"422766019","full_name":"rbroderi/protocol_implements_decorator","owner":"rbroderi","description":null,"archived":false,"fork":false,"pushed_at":"2024-08-12T17:47:22.000Z","size":464,"stargazers_count":1,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-24T22:09:52.632Z","etag":null,"topics":["decorators-python","implement","protocol"],"latest_commit_sha":null,"homepage":"https://rbroderi.github.io/protocol_implements_decorator/","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/rbroderi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2021-10-30T02:41:54.000Z","updated_at":"2024-04-28T16:16:06.000Z","dependencies_parsed_at":"2024-04-23T04:46:03.372Z","dependency_job_id":null,"html_url":"https://github.com/rbroderi/protocol_implements_decorator","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/rbroderi/protocol_implements_decorator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbroderi%2Fprotocol_implements_decorator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbroderi%2Fprotocol_implements_decorator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbroderi%2Fprotocol_implements_decorator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbroderi%2Fprotocol_implements_decorator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rbroderi","download_url":"https://codeload.github.com/rbroderi/protocol_implements_decorator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rbroderi%2Fprotocol_implements_decorator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28477203,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T03:13:13.607Z","status":"ssl_error","status_checked_at":"2026-01-16T03:11:47.863Z","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":["decorators-python","implement","protocol"],"created_at":"2026-01-16T03:27:20.727Z","updated_at":"2026-01-16T03:27:20.838Z","avatar_url":"https://github.com/rbroderi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Protocol Implements Decorator\n================================================\n\u003c!-- [![GitHub License](https://img.shields.io/github/license/rbroderi/Verbex)](https://github.com/rbroderi/Verbex/blob/master/LICENSE) --\u003e\n[![Generic badge](https://img.shields.io/badge/license-GPL‐3.0-orange.svg)](https://github.com/rbroderi/protocol_implements_decorator/blob/master/LICENSE)\n[![Code style: black](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n[![PyPI pyversions](https://img.shields.io/pypi/pyversions/protocol_implements_decorator)](https://pypi.python.org/pypi/protocol_implements_decorator/)\n[![Generic badge](https://img.shields.io/badge/mypy-typed-purple.svg)](http://mypy-lang.org/)\n[![Generic badge](https://img.shields.io/badge/beartype-runtime_typed-cyan.svg)](https://github.com/beartype/beartype)\n[![Generic badge](https://img.shields.io/badge/bandit-checked-magenta.svg)](https://bandit.readthedocs.io/en/latest/)\n[![Generic badge](https://img.shields.io/badge/uv-requirements-yellow.svg)](https://github.com/astral-sh/uv)\n[![Dynamic TOML Badge](https://img.shields.io/badge/dynamic/toml?url=https%3A%2F%2Fraw.githubusercontent.com%2Frbroderi%2Fprotocol_implements_decorator%2Fmaster%2Fpyproject.toml\u0026query=%24.project.version\u0026label=Version)](https://github.com/rbroderi/protocol_implements_decorator/releases)\n\n\nAdds the \"implements\" decorator to make using protocols easier and more explicit\n\n\n## Description\n\nAdds the @implements decorator.\nThis will cause a runtime NotImplementedError if the class does not implement all parts of the protocol.\nAlso adds the get_protocols_implemented method to the class providing a list of all protocols the decorated class adhears to.\n\nUsage:\n---\nTwo example protocols\n\n```python\nclass Printable(Protocol):\n  \"\"\"A test protocol that requires a to_string method.\"\"\"\n\n  def to_string(self) -\u003e str:\n    return \"\"\n\nclass Otherable(Protocol):\n  \"\"\"Another example.\"\"\"\n\n  def other(self) -\u003e str:\n    return \"\n```\n\n---\nExample of one protocol\n\n```python\n@implements(Printable)\nclass Example2:\n\n  def to_string(self) -\u003e str:\n    return str(self)\n```\n\nFor multiple protocols you can chain dectorator or include in a list in one dectorator\n```python\n@implements(Printable)\n@implements(Otherable)\nclass Example1:\n  \"\"\"Test class that uses multiple protocols.\"\"\"\n\n  def to_string(self) -\u003e str:\n    return str(self)\n\n  def other(self) -\u003e str:\n    return str(self)\n\n\n@implements(Printable, Otherable)\nclass Example2:\n  \"\"\"Test class that uses multiple protocols.\"\"\"\n\n  def to_string(self) -\u003e str:\n    return str(self)\n\n  def other(self) -\u003e str:\n    return str(self)\n```\n\nErrors\n---\nThis will cause a runtime error as it doesn't implement the Printable protocol\n\n```python\n@implements(Printable, Otherable)\nclass Example2:\n  \"\"\"Test class that uses multiple protocols.\"\"\"\n\n  def other(self) -\u003e str:\n    return str(self)\n```\n```text\nNotImplementedError: test.\u003clocals\u003e.Printable requires implentation of ['to_string']\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frbroderi%2Fprotocol_implements_decorator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frbroderi%2Fprotocol_implements_decorator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frbroderi%2Fprotocol_implements_decorator/lists"}