# ODRE Framework
## Quickstart
#### Install
```bash
pip install pyodre
```
#### Enforce ODRL policies
```python
from pyodre.odre import ODRE
policy = """
{
"@context": "http://www.w3.org/ns/odrl.jsonld",
"@type": "Offer",
"uid": "http://example.com/policy:6163",
"profile": "http://example.com/odrl:profile:10",
"permission": [{
"target": "http://example.com/document:1234",
"assigner": "http://example.com/org:616",
"action": "distribute",
"constraint": [{
"leftOperand": "dateTime",
"operator": "lt",
"rightOperand": { "@value": "2025-01-01", "@type": "xsd:date" }
}]
}]
}
"""
usage_decision = ODRE().enforce(policy)
print(usage_decision)
```
In the case a user wants to activate the DEBUG mode that shows the interpretable policies, the actions and the usage decision the following excerpt must be used. In addition, note that the interpreter can be modified
```python
usage_decision = ODRE().set_debug(True).set_interpreter(PythonInterpreter()).enforce(policy)
print(usage_decision)
```
#### Register new functions (descriptive + interpretable)
TBD
### Interpolation
The policy templating is based on the Jinja language, it can be used to pass data variables that are not hardcoded in the policy increasing its privacy or it can be used to pass python native functions so they can be expressed in the policy and invoked during the enforcement.
In the following example a variable `{{token}}` is expressed in the policy and, as left operand, the function `{{retrieve_token()}}` is used. Note that the value of both is passed to the `ODRE` object under the parameter `interpolations`
```python
policy = """
{
"@context": "http://www.w3.org/ns/odrl.jsonld",
"@type": "Offer",
"uid": "http://example.com/policy:6163",
"profile": "http://example.com/odrl:profile:10",
"permission": [{
"target": "http://example.com/document:1234",
"assigner": "http://example.com/org:616",
"action": "distribute",
"constraint": [{
"leftOperand": "dateTime",
"operator": "lt",
"rightOperand": { "@value": "2025-01-01", "@type": "xsd:date" }
},{
"leftOperand": { "@value": "{{retrieve_token()}}" , "@type": "xsd:string" },
"operator": "eq",
"rightOperand": { "@value": "{{token}}", "@type": "xsd:string" }
}]
}]
}
"""
def get_token():
return "AAA"
usage_decision = ODRE().set_debug(True).enforce(policy, interpolations={'token' : 'AAA', 'retrieve_token' : get_token})
print(usage_decision)
```
## Supported features
### ODRL operantors
| Operators | Implementation status | # |
|--|--| -- |
| [eq](https://www.w3.org/TR/odrl-vocab/#term-eq) | supported | ✓ |
| [gt](https://www.w3.org/TR/odrl-vocab/#term-gt) | supported | ✓ |
| [gteq](https://www.w3.org/TR/odrl-vocab/#term-gteq) | unsupported | ✓ |
| [lt](https://www.w3.org/TR/odrl-vocab/#term-lt) | supported | ✓ |
| [lteq](https://www.w3.org/TR/odrl-vocab/#term-lteq) | supported | ✓ |
| [neq](https://www.w3.org/TR/odrl-vocab/#term-neq) | supported | ✓ |
| [hasPart](https://www.w3.org/TR/odrl-vocab/#term-hasPart) | unsupported | ✗ |
| [isA](https://www.w3.org/TR/odrl-vocab/#term-isA) | unsupported | ✗ |
| [isAllOf](https://www.w3.org/TR/odrl-vocab/#term-isAllOf) | unsupported | ✗ |
| [isAnyOf](https://www.w3.org/TR/odrl-vocab/#term-isAnyOf) | unsupported | ✗ |
| [isNoneOf](https://www.w3.org/TR/odrl-vocab/#term-isNoneOf) | unsupported | ✗ |
| [isPartOf](https://www.w3.org/TR/odrl-vocab/#term-isPartOf) | unsupported | ✗ |
### ODRL operands
* The available implemented [Left Operands](https://www.w3.org/TR/odrl-vocab/#term-LeftOperand) from those specified in the [ODRL Vocabulary & Expression 2.2](https://www.w3.org/TR/odrl-vocab/) are the following:
| Left Operands | Implementation status | # |
|---------------------------------------------------------------------------------------------|--| -- |
| [absolutePosition](https://www.w3.org/TR/odrl-vocab/#term-absolutePosition) | unsupported | ✗ |
| [absoluteSize](https://www.w3.org/TR/odrl-vocab/#term-absoluteSize) | unsupported | ✗ |
| [absoluteSpatialPosition](https://www.w3.org/TR/odrl-vocab/#term-absoluteSpatialPosition) | unsupported | ✗ |
| [absoluteTemporalPosition](https://www.w3.org/TR/odrl-vocab/#term-absoluteTemporalPosition) | unsupported | ✗ |
| [count](https://www.w3.org/TR/odrl-vocab/#term-count) | unsupported | ✗ |
| [dateTime](https://www.w3.org/TR/odrl-vocab/#term-dateTime) | unsupported | ✗ |
| [delayPeriod](https://www.w3.org/TR/odrl-vocab/#term-delayPeriod) | unsupported | ✗ |
| [deliveryChannel](https://www.w3.org/TR/odrl-vocab/#term-deliveryChannel) | unsupported | ✗ |
| [device](https://www.w3.org/TR/odrl-vocab/#term-device) | unsupported | ✗ |
| [elapsedTime](https://www.w3.org/TR/odrl-vocab/#term-elapsedTime) | unsupported | ✗ |
| [event](https://www.w3.org/TR/odrl-vocab/#term-event) | unsupported | ✗ |
| [fileFormat](https://www.w3.org/TR/odrl-vocab/#term-fileFormat) | unsupported | ✗ |
| [industry](https://www.w3.org/TR/odrl-vocab/#term-industry) | unsupported | ✗ |
| [language](https://www.w3.org/TR/odrl-vocab/#term-language) | unsupported | ✗ |
| [media](https://www.w3.org/TR/odrl-vocab/#term-media) | unsupported | ✗ |
| [meteredTime](https://www.w3.org/TR/odrl-vocab/#term-meteredTime) | unsupported | ✗ |
| [payAmount](https://www.w3.org/TR/odrl-vocab/#term-payAmount) | unsupported | ✗ |
| [percentage](https://www.w3.org/TR/odrl-vocab/#term-percentage) | unsupported | ✗ |
| [product](https://www.w3.org/TR/odrl-vocab/#term-product) | unsupported | ✗ |
| [purpose](https://www.w3.org/TR/odrl-vocab/#term-purpose) | unsupported | ✗ |
| [recipient](https://www.w3.org/TR/odrl-vocab/#term-recipient) | unsupported | ✗ |
| [relativePosition](https://www.w3.org/TR/odrl-vocab/#term-relativePosition) | unsupported | ✗ |
| [relativeSize](https://www.w3.org/TR/odrl-vocab/#term-relativeSize) | unsupported | ✗ |
| [relativeSpatialPosition](https://www.w3.org/TR/odrl-vocab/#term-relativeSpatialPosition) | unsupported | ✗ |
| [relativeTemporalPosition](https://www.w3.org/TR/odrl-vocab/#term-relativeTemporalPosition) | unsupported | ✗ |
| [resolution](https://www.w3.org/TR/odrl-vocab/#term-resolution) | unsupported | ✗ |
| [spatial](https://www.w3.org/TR/odrl-vocab/#term-spatial) | unsupported | ✗ |
| [spatialCoordinates](https://www.w3.org/TR/odrl-vocab/#term-spatialCoordinates) | unsupported | ✗ |
| [system](https://www.w3.org/TR/odrl-vocab/#term-system) | unsupported | ✗ |
| [systemDevice](https://www.w3.org/TR/odrl-vocab/#term-systemDevice) | unsupported | ✗ |
| [timeInterval](https://www.w3.org/TR/odrl-vocab/#term-timeInterval) | unsupported | ✗ |
| [unitOfCount](https://www.w3.org/TR/odrl-vocab/#term-unitOfCount) | unsupported | ✗ |
| [version](https://www.w3.org/TR/odrl-vocab/#term-version) | unsupported | ✗ |
| [virtualLocation](https://www.w3.org/TR/odrl-vocab/#term-virtualLocation) | unsupported | ✗ |
* The available implemented [Right Operands](https://www.w3.org/TR/odrl-vocab/#term-RightOperand) from those specified in the [ODRL Vocabulary & Expression 2.2](https://www.w3.org/TR/odrl-vocab/) are the following:
| Right Operands | Implementation status | # |
|--|--| -- |
| [policyUsage](https://www.w3.org/TR/odrl-vocab/#term-policyUsage) | unsupported | ✗ |
### ODRL actions
* The available implemented [Right Operands](https://www.w3.org/TR/odrl-vocab/#term-RightOperand) from those specified in the [ODRL Vocabulary & Expression 2.2](https://www.w3.org/TR/odrl-vocab/) are the following:
| Actions | Implementation status | # |
|-------------------------------------------------------------------|--| -- |
| [policyUsage](https://www.w3.org/TR/odrl-vocab/#term-policyUsage) | unsupported | ✗ |
### Extensions
In order to include new operators or operands a user must provide their name space and a function prefix for it. For instance, the new function <http://XXXXX> and its function prefix fnc_. Then, the user must implement the function fnc_XX in the file python functions
Raw data
{
"_id": null,
"home_page": "https://github.com/ODRE-Framework/odre-python",
"name": "pyodre",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": null,
"author": "Andrea Cimmino",
"author_email": "andreajesus.cimmino@upm.es",
"download_url": "https://files.pythonhosted.org/packages/ca/9c/dde58a9b46282d7551f3d1e1d7123c5dc712d3a5db871b50a4805536fdaf/pyodre-1.0.3.tar.gz",
"platform": null,
"description": "# ODRE Framework\n\n\n\n\n## Quickstart\n\n#### Install\n\n```bash\npip install pyodre\n```\n\n#### Enforce ODRL policies\n\n```python\nfrom pyodre.odre import ODRE\n\npolicy = \"\"\"\n{\n \"@context\": \"http://www.w3.org/ns/odrl.jsonld\",\n \"@type\": \"Offer\",\n \"uid\": \"http://example.com/policy:6163\",\n \"profile\": \"http://example.com/odrl:profile:10\",\n \"permission\": [{\n \"target\": \"http://example.com/document:1234\",\n \"assigner\": \"http://example.com/org:616\",\n \"action\": \"distribute\",\n \"constraint\": [{\n \"leftOperand\": \"dateTime\",\n \"operator\": \"lt\",\n \"rightOperand\": { \"@value\": \"2025-01-01\", \"@type\": \"xsd:date\" }\n }]\n }]\n}\n\"\"\"\nusage_decision = ODRE().enforce(policy)\nprint(usage_decision)\n```\n\nIn the case a user wants to activate the DEBUG mode that shows the interpretable policies, the actions and the usage decision the following excerpt must be used. In addition, note that the interpreter can be modified\n\n```python\nusage_decision = ODRE().set_debug(True).set_interpreter(PythonInterpreter()).enforce(policy)\nprint(usage_decision)\n```\n\n#### Register new functions (descriptive + interpretable)\nTBD\n\n### Interpolation\n\nThe policy templating is based on the Jinja language, it can be used to pass data variables that are not hardcoded in the policy increasing its privacy or it can be used to pass python native functions so they can be expressed in the policy and invoked during the enforcement.\n\nIn the following example a variable `{{token}}` is expressed in the policy and, as left operand, the function `{{retrieve_token()}}` is used. Note that the value of both is passed to the `ODRE` object under the parameter `interpolations`\n\n```python\npolicy = \"\"\"\n{\n \"@context\": \"http://www.w3.org/ns/odrl.jsonld\",\n \"@type\": \"Offer\",\n \"uid\": \"http://example.com/policy:6163\",\n \"profile\": \"http://example.com/odrl:profile:10\",\n \"permission\": [{\n \"target\": \"http://example.com/document:1234\",\n \"assigner\": \"http://example.com/org:616\",\n \"action\": \"distribute\",\n \"constraint\": [{\n \"leftOperand\": \"dateTime\",\n \"operator\": \"lt\",\n \"rightOperand\": { \"@value\": \"2025-01-01\", \"@type\": \"xsd:date\" }\n },{\n \"leftOperand\": { \"@value\": \"{{retrieve_token()}}\" , \"@type\": \"xsd:string\" },\n \"operator\": \"eq\",\n \"rightOperand\": { \"@value\": \"{{token}}\", \"@type\": \"xsd:string\" }\n }]\n }]\n}\n\"\"\"\n\ndef get_token():\n return \"AAA\"\n\nusage_decision = ODRE().set_debug(True).enforce(policy, interpolations={'token' : 'AAA', 'retrieve_token' : get_token})\nprint(usage_decision)\n```\n\n\n## Supported features\n\n### ODRL operantors\n\n| Operators | Implementation status | # |\n|--|--| -- |\n| [eq](https://www.w3.org/TR/odrl-vocab/#term-eq) | supported | ✓ |\n| [gt](https://www.w3.org/TR/odrl-vocab/#term-gt) | supported | ✓ |\n| [gteq](https://www.w3.org/TR/odrl-vocab/#term-gteq) | unsupported | ✓ |\n| [lt](https://www.w3.org/TR/odrl-vocab/#term-lt) | supported | ✓ |\n| [lteq](https://www.w3.org/TR/odrl-vocab/#term-lteq) | supported | ✓ |\n| [neq](https://www.w3.org/TR/odrl-vocab/#term-neq) | supported | ✓ |\n| [hasPart](https://www.w3.org/TR/odrl-vocab/#term-hasPart) | unsupported | ✗ |\n| [isA](https://www.w3.org/TR/odrl-vocab/#term-isA) | unsupported | ✗ |\n| [isAllOf](https://www.w3.org/TR/odrl-vocab/#term-isAllOf) | unsupported | ✗ |\n| [isAnyOf](https://www.w3.org/TR/odrl-vocab/#term-isAnyOf) | unsupported | ✗ |\n| [isNoneOf](https://www.w3.org/TR/odrl-vocab/#term-isNoneOf) | unsupported | ✗ |\n| [isPartOf](https://www.w3.org/TR/odrl-vocab/#term-isPartOf) | unsupported | ✗ |\n\n### ODRL operands\n* The available implemented [Left Operands](https://www.w3.org/TR/odrl-vocab/#term-LeftOperand) from those specified in the [ODRL Vocabulary & Expression 2.2](https://www.w3.org/TR/odrl-vocab/) are the following:\n\n| Left Operands | Implementation status | # |\n|---------------------------------------------------------------------------------------------|--| -- |\n| [absolutePosition](https://www.w3.org/TR/odrl-vocab/#term-absolutePosition) | unsupported | ✗ |\n| [absoluteSize](https://www.w3.org/TR/odrl-vocab/#term-absoluteSize) | unsupported | ✗ |\n| [absoluteSpatialPosition](https://www.w3.org/TR/odrl-vocab/#term-absoluteSpatialPosition) | unsupported | ✗ |\n| [absoluteTemporalPosition](https://www.w3.org/TR/odrl-vocab/#term-absoluteTemporalPosition) | unsupported | ✗ |\n| [count](https://www.w3.org/TR/odrl-vocab/#term-count) | unsupported | ✗ |\n| [dateTime](https://www.w3.org/TR/odrl-vocab/#term-dateTime) | unsupported | ✗ |\n| [delayPeriod](https://www.w3.org/TR/odrl-vocab/#term-delayPeriod) | unsupported | ✗ |\n| [deliveryChannel](https://www.w3.org/TR/odrl-vocab/#term-deliveryChannel) | unsupported | ✗ |\n| [device](https://www.w3.org/TR/odrl-vocab/#term-device) | unsupported | ✗ |\n| [elapsedTime](https://www.w3.org/TR/odrl-vocab/#term-elapsedTime) | unsupported | ✗ |\n| [event](https://www.w3.org/TR/odrl-vocab/#term-event) | unsupported | ✗ |\n| [fileFormat](https://www.w3.org/TR/odrl-vocab/#term-fileFormat) | unsupported | ✗ |\n| [industry](https://www.w3.org/TR/odrl-vocab/#term-industry) | unsupported | ✗ |\n| [language](https://www.w3.org/TR/odrl-vocab/#term-language) | unsupported | ✗ |\n| [media](https://www.w3.org/TR/odrl-vocab/#term-media) | unsupported | ✗ |\n| [meteredTime](https://www.w3.org/TR/odrl-vocab/#term-meteredTime) | unsupported | ✗ |\n| [payAmount](https://www.w3.org/TR/odrl-vocab/#term-payAmount) | unsupported | ✗ |\n| [percentage](https://www.w3.org/TR/odrl-vocab/#term-percentage) | unsupported | ✗ |\n| [product](https://www.w3.org/TR/odrl-vocab/#term-product) | unsupported | ✗ |\n| [purpose](https://www.w3.org/TR/odrl-vocab/#term-purpose) | unsupported | ✗ |\n| [recipient](https://www.w3.org/TR/odrl-vocab/#term-recipient) | unsupported | ✗ |\n| [relativePosition](https://www.w3.org/TR/odrl-vocab/#term-relativePosition) | unsupported | ✗ |\n| [relativeSize](https://www.w3.org/TR/odrl-vocab/#term-relativeSize) | unsupported | ✗ |\n| [relativeSpatialPosition](https://www.w3.org/TR/odrl-vocab/#term-relativeSpatialPosition) | unsupported | ✗ |\n| [relativeTemporalPosition](https://www.w3.org/TR/odrl-vocab/#term-relativeTemporalPosition) | unsupported | ✗ |\n| [resolution](https://www.w3.org/TR/odrl-vocab/#term-resolution) | unsupported | ✗ |\n| [spatial](https://www.w3.org/TR/odrl-vocab/#term-spatial) | unsupported | ✗ |\n| [spatialCoordinates](https://www.w3.org/TR/odrl-vocab/#term-spatialCoordinates) | unsupported | ✗ |\n| [system](https://www.w3.org/TR/odrl-vocab/#term-system) | unsupported | ✗ |\n| [systemDevice](https://www.w3.org/TR/odrl-vocab/#term-systemDevice) | unsupported | ✗ |\n| [timeInterval](https://www.w3.org/TR/odrl-vocab/#term-timeInterval) | unsupported | ✗ |\n| [unitOfCount](https://www.w3.org/TR/odrl-vocab/#term-unitOfCount) | unsupported | ✗ |\n| [version](https://www.w3.org/TR/odrl-vocab/#term-version) | unsupported | ✗ |\n| [virtualLocation](https://www.w3.org/TR/odrl-vocab/#term-virtualLocation) | unsupported | ✗ |\n\n\n* The available implemented [Right Operands](https://www.w3.org/TR/odrl-vocab/#term-RightOperand) from those specified in the [ODRL Vocabulary & Expression 2.2](https://www.w3.org/TR/odrl-vocab/) are the following:\n\n| Right Operands | Implementation status | # |\n|--|--| -- |\n| [policyUsage](https://www.w3.org/TR/odrl-vocab/#term-policyUsage) | unsupported | ✗ |\n\n### ODRL actions\n\n* The available implemented [Right Operands](https://www.w3.org/TR/odrl-vocab/#term-RightOperand) from those specified in the [ODRL Vocabulary & Expression 2.2](https://www.w3.org/TR/odrl-vocab/) are the following:\n\n| Actions | Implementation status | # |\n|-------------------------------------------------------------------|--| -- |\n| [policyUsage](https://www.w3.org/TR/odrl-vocab/#term-policyUsage) | unsupported | ✗ |\n\n\n### Extensions\n\nIn order to include new operators or operands a user must provide their name space and a function prefix for it. For instance, the new function <http://XXXXX> and its function prefix fnc_. Then, the user must implement the function fnc_XX in the file python functions\n",
"bugtrack_url": null,
"license": null,
"summary": "Open Digital Rights Enforcement Framework python implementation",
"version": "1.0.3",
"project_urls": {
"Homepage": "https://github.com/ODRE-Framework/odre-python"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f311a5277b89d40b61dce85124b1cf04ffc1c809d7b0850d19efc37ce31ba473",
"md5": "a46b41a44678f563282fc5b067f5e971",
"sha256": "63fab7fb853369424adc5cf9c69aca5c314868cf50084c5137e2368a2082fee9"
},
"downloads": -1,
"filename": "pyodre-1.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a46b41a44678f563282fc5b067f5e971",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 13778,
"upload_time": "2024-09-06T09:52:14",
"upload_time_iso_8601": "2024-09-06T09:52:14.007117Z",
"url": "https://files.pythonhosted.org/packages/f3/11/a5277b89d40b61dce85124b1cf04ffc1c809d7b0850d19efc37ce31ba473/pyodre-1.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ca9cdde58a9b46282d7551f3d1e1d7123c5dc712d3a5db871b50a4805536fdaf",
"md5": "cc1a2b47710165f926b8dc79c312dc23",
"sha256": "e4526e5a8951cce291c7e3de6a22993af8f8ebb543d10d920e9050ebd7b89055"
},
"downloads": -1,
"filename": "pyodre-1.0.3.tar.gz",
"has_sig": false,
"md5_digest": "cc1a2b47710165f926b8dc79c312dc23",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 14368,
"upload_time": "2024-09-06T09:52:15",
"upload_time_iso_8601": "2024-09-06T09:52:15.633389Z",
"url": "https://files.pythonhosted.org/packages/ca/9c/dde58a9b46282d7551f3d1e1d7123c5dc712d3a5db871b50a4805536fdaf/pyodre-1.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-06 09:52:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ODRE-Framework",
"github_project": "odre-python",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pyodre"
}