{"id":13787793,"url":"https://github.com/heliconhq/opa-python","last_synced_at":"2025-05-12T01:31:38.123Z","repository":{"id":64668573,"uuid":"577089623","full_name":"heliconhq/opa-python","owner":"heliconhq","description":"Python client library for Open Policy Framework (OPA).","archived":false,"fork":false,"pushed_at":"2022-12-14T23:20:07.000Z","size":65,"stargazers_count":2,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-03T10:02:57.040Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://opa-python.readthedocs.io/en/latest/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/heliconhq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-12-11T23:30:09.000Z","updated_at":"2025-03-11T13:15:39.000Z","dependencies_parsed_at":"2023-01-29T01:30:29.307Z","dependency_job_id":null,"html_url":"https://github.com/heliconhq/opa-python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heliconhq%2Fopa-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heliconhq%2Fopa-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heliconhq%2Fopa-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heliconhq%2Fopa-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heliconhq","download_url":"https://codeload.github.com/heliconhq/opa-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253659389,"owners_count":21943628,"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-08-03T21:00:31.279Z","updated_at":"2025-05-12T01:31:37.821Z","avatar_url":"https://github.com/heliconhq.png","language":"Python","funding_links":[],"categories":["Language and Platform Integrations"],"sub_categories":["Python"],"readme":"# OPA Python\n\nPython client library for Open Policy Framework (OPA).\n\n## Installation\n\n    python -m pip install opa-python\n    \n## Compatibility\n\nThe library has been tested with:\n\n- Python 3.10\n- OPA 0.47.3\n    \n## Usage\n\nCreate a client instance:\n\n```python\n\u003e\u003e\u003e from opa import OPAClient\n\u003e\u003e\u003e client = OPAClient(url=\"http://opa-server/\")\n```\n\nVerify that the OPA server is up and ready to accept requests:\n\n```python\n\u003e\u003e\u003e client.check_health()\nTrue\n```\n    \nCreate or update a document:\n\n```python\n\u003e\u003e\u003e data = {\n...    \"users\": [\n...        \"bilbo\",\n...        \"frodo\",\n...        \"gandalf\",\n...    ],\n... }\n\u003e\u003e\u003e client.save_document(\"my.data\", data)\n```\n    \nCreate or update a policy:\n\n```python\n\u003e\u003e\u003e policy = \"\"\"\n... package my.policy\n... \n... default allow := false\n... \n... allow {\n...     data.my.data.users[_] = input.name\n... }\n... \"\"\"\n\u003e\u003e\u003e client.save_policy(\"policy-id\", policy)\n{}\n```\n    \nRequest decisions by evaluating input against the policy and data:\n\n```python\n\u003e\u003e\u003e client.check_policy(\"my.policy.allow\", {\"name\": \"bilbo\"})\nTrue\n\n\u003e\u003e\u003e client.check_policy(\"my.policy.allow\", {\"name\": \"sauron\"})\nFalse\n```\n\nYou can find the full reference in the \n[documentation](https://opa-python.readthedocs.io/en/latest/).\n\n## Local installation\n\nInstall [Poetry](https://python-poetry.org/), create new environment and\ninstall the dependencies:\n\n    poetry install\n    \n## Running the test suite\n\nNOTE: Each individual test that communicates with OPA creates a fresh Docker\ncontainer. This is pretty neat from a testing perspective, but means that\nrunning the entire suite takes a bit of time.\n\nMake sure you do not have any services listening to `8181` when you start the\ntests! We might add a configuration for setting the port later, or run the\ntests in Docker as well.\n\nRun the tests:\n\n    poetry run pytest\n    \nRun specific test module:\n\n    poetry run pytest tests/test_integration.py\n    \n## Publishing\n\nSet your credentials:\n\n    poetry config pypi-token.pypi \u003ctoken\u003e\n\nBuild and publish:\n\n    poetry publish --build\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheliconhq%2Fopa-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheliconhq%2Fopa-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheliconhq%2Fopa-python/lists"}