OPA Python
Python client library for Open Policy Framework (OPA).
Installation
python -m pip install opa-python
Compatibility
The library has been tested with:
- Python 3.10
- OPA 0.47.3
Usage
Create a client instance:
>>> from opa import OPAClient
>>> client = OPAClient(url="http://opa-server/")
Verify that the OPA server is up and ready to accept requests:
>>> client.check_health()
True
Create or update a document:
>>> data = {
... "users": [
... "bilbo",
... "frodo",
... "gandalf",
... ],
... }
>>> client.save_document("my.data", data)
Create or update a policy:
>>> policy = """
... package my.policy
...
... default allow := false
...
... allow {
... data.my.data.users[_] = input.name
... }
... """
>>> client.save_policy("policy-id", policy)
{}
Request decisions by evaluating input against the policy and data:
>>> client.check_policy("my.policy.allow", {"name": "bilbo"})
True
>>> client.check_policy("my.policy.allow", {"name": "sauron"})
False
You can find the full reference in the documentation.
Local installation
Install Poetry, create new environment and install the dependencies:
poetry install
Running the test suite
NOTE: Each individual test that communicates with OPA creates a fresh Docker container. This is pretty neat from a testing perspective, but means that running the entire suite takes a bit of time.
Make sure you do not have any services listening to 8181 when you start the
tests! We might add a configuration for setting the port later, or run the
tests in Docker as well.
Run the tests:
poetry run pytest
Run specific test module:
poetry run pytest tests/test_integration.py
Publishing
Set your credentials:
poetry config pypi-token.pypi <token>
Build and publish:
poetry publish --build
Metadata
Release files for opa-python 0.0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| opa_python-0.0.9.tar.gz | 9.1 kB | Without provenance | Details for opa_python-0.0.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| opa_python-0.0.9-py3-none-any.whl | Python 3 | none | any | Details for opa_python-0.0.9-py3-none-any.whl |
Total release size: 19.0 kB
Release files / opa_python-0.0.9.tar.gz
| Download URL | opa_python-0.0.9.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ba59231275fb12da5d9907aaa8dd072daf0cf666b675c5d51aebf95dcfd6541
|
|
BLAKE2b-256 checksum How to use checksums |
5afbdc447d3f712f23ef2a62b429fd60b11d6033dcfbf5a4a780f0d6ca6a6745
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.0 CPython/3.13.2 Linux/6.13.3-arch1-1
|
Release files / opa_python-0.0.9-py3-none-any.whl
| Download URL | opa_python-0.0.9-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0dc658241ebce96dfdc1feead11ed87147bae9b36f5fbd743ee6d36c5d4aadd2
|
|
BLAKE2b-256 checksum How to use checksums |
d58c3abfdc8ac46212eb611bc5a7730f14fac569a4be27612551127e2c22bfab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.0 CPython/3.13.2 Linux/6.13.3-arch1-1
|
Security for opa-python 0.0.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.