{"id":13787806,"url":"https://github.com/open-policy-agent/rego-python","last_synced_at":"2026-03-14T14:04:01.732Z","repository":{"id":48652538,"uuid":"139075854","full_name":"open-policy-agent/rego-python","owner":"open-policy-agent","description":"Python library for interacting with Rego ASTs.","archived":false,"fork":false,"pushed_at":"2021-07-15T18:21:36.000Z","size":11,"stargazers_count":50,"open_issues_count":1,"forks_count":16,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-06-23T20:04:19.292Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/open-policy-agent.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":"2018-06-28T22:54:19.000Z","updated_at":"2025-05-30T07:03:01.000Z","dependencies_parsed_at":"2022-09-10T23:31:37.248Z","dependency_job_id":null,"html_url":"https://github.com/open-policy-agent/rego-python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/open-policy-agent/rego-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-policy-agent%2Frego-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-policy-agent%2Frego-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-policy-agent%2Frego-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-policy-agent%2Frego-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/open-policy-agent","download_url":"https://codeload.github.com/open-policy-agent/rego-python/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-policy-agent%2Frego-python/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268689953,"owners_count":24291080,"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","status":"online","status_checked_at":"2025-08-04T02:00:09.867Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":"2024-08-03T21:00:31.590Z","updated_at":"2026-03-14T14:03:56.673Z","avatar_url":"https://github.com/open-policy-agent.png","language":"Python","readme":"# rego-python\n\nThis repository contains a Python package for interacting with the [Open Policy Agent](https://github.com/open-policy-agent/opa) project's policy language: [Rego](https://www.openpolicyagent.org/docs/how-do-i-write-policies.html).\n\n## Overview\n\nmodule | description\n--- | ---\n`ast` | contains types representing Abstract Syntax Tree (AST) nodes in Rego.\n`walk` | contains a visitor pattern implementation for `ast` types.\n\n## Example: Load Rego AST from JSON\n\n```python\nimport json\nimport requests\n\nfrom rego import ast, walk\n\n# Load some pi into OPA as data (yum!)\nrequests.put(\"http://localhost:8181/v1/data\", data=json.dumps({\n    \"pi\": 3.14,\n}))\n\n# Use OPA's Compile API to partially evaluate a query. Treat 'input.radius' as unknown.\nresp = requests.post(\"http://localhost:8181/v1/compile\", json.dumps({\n    \"query\": \"(data.pi * input.radius * 2) \u003e= input.min_radius\",\n    \"input\": {\n        \"min_radius\": 4,\n    },\n    \"unknowns\": [\"input.radius\"],\n}))\n\n# Load the resulting set of query ASTs out of the JSON response.\ntree = resp.json()[\"result\"][\"queries\"]\nqs = ast.QuerySet.from_data(tree)\n\n# Pretty print the ASTs.\nwalk.pretty_print(qs)\n```\n\nIn a new terminal:\n\n```\n$ opa run --server\n```\n\nIn another terminal, run the example.\n\n```bash\n$ git clone https://github.com/open-policy-agent/rego-python.git\n$ cd rego-python\n$ virtualenv env\n$ source env/bin/activate\n$ pip install -r example-requirements.txt\n$ pip install -e .\n$ python example.py\n```\n\nExample output.\n\n```bash\nQuerySet (1 queries)\n  Query (1 exprs)\n    Expr\n      Term\n        Ref\n          Term\n            Var(gte)\n      Term\n        Call\n          Term\n            Ref\n              Term\n                Var(mul)\n          Term\n            Call\n              Term\n                Ref\n                  Term\n                    Var(mul)\n              Term\n                Scalar(3.14)\n              Term\n                Ref\n                  Term\n                    Var(input)\n                  Term\n                    Scalar(radius)\n          Term\n            Scalar(2)\n      Term\n        Scalar(4)\n```","funding_links":[],"categories":["Language and Platform Integrations"],"sub_categories":["Python"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-policy-agent%2Frego-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopen-policy-agent%2Frego-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-policy-agent%2Frego-python/lists"}