Skip to main content

ODRE Framework

License

This is a pythom impementation of the ODRE approach to enforce ODRL policices. You can play with this implementation in our demo.

Quickstart

Install

pip install pyodre

Enforce ODRL policies

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

usage_decision = ODRE().set_debug(True).set_interpreter(PythonInterpreter()).enforce(policy)
print(usage_decision)

Register new functions (descriptive + interpretable)

In order to include new operators or operands a user must provide the name space and a function prefix for the terms in the ontology extensions that is been integrated in ODRE. To do this, the user must include this information in the Interpreter class; for instance, a new function namespace prefix fnc: <http://organiation.org/namespace> and its function prefix fnc_. Then, the user must implement the function fnc_XX in the file python functions considering that XX should meet the term in the ontology, for instance the python function fnc_time will be called if the policy contains the term fnc:time.

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

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 supported ✓
gt supported ✓
gteq supported ✓
lt supported ✓
lteq supported ✓
neq supported ✓
hasPart unsupported ✗
isA unsupported ✗
isAllOf unsupported ✗
isAnyOf unsupported ✗
isNoneOf unsupported ✗
isPartOf unsupported ✗

ODRL operands

Left Operands Implementation status #
absolutePosition unsupported ✗
absoluteSize unsupported ✗
absoluteSpatialPosition unsupported ✗
absoluteTemporalPosition unsupported ✗
count unsupported ✗
dateTime supported ✓
delayPeriod unsupported ✗
deliveryChannel unsupported ✗
device unsupported ✗
elapsedTime unsupported ✗
event unsupported ✗
fileFormat unsupported ✗
industry unsupported ✗
language unsupported ✗
media unsupported ✗
meteredTime unsupported ✗
payAmount unsupported ✗
percentage unsupported ✗
product unsupported ✗
purpose unsupported ✗
recipient unsupported ✗
relativePosition unsupported ✗
relativeSize unsupported ✗
relativeSpatialPosition unsupported ✗
relativeTemporalPosition unsupported ✗
resolution unsupported ✗
spatial unsupported ✗
spatialCoordinates unsupported ✗
system unsupported ✗
systemDevice unsupported ✗
timeInterval unsupported ✗
unitOfCount unsupported ✗
version unsupported ✗
virtualLocation unsupported ✗
Right Operands Implementation status #
policyUsage unsupported ✗

ODRL actions

Actions Implementation status #
policyUsage unsupported ✗

BibTeX Citation

@misc{cimmino2024opendigitalrightsenforcement,
      title={Open Digital Rights Enforcement Framework (ODRE): from descriptive to enforceable policies}, 
      author={Andrea Cimmino and Juan Cano-Benito and Raúl García-Castro},
      year={2024},
      eprint={2409.17602},
      archivePrefix={arXiv},
      primaryClass={cs.CR},
      url={https://arxiv.org/abs/2409.17602}, 
}

Metadata

Release files for pyodre 1.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyodre 1.0.6
File Size Uploaded
pyodre-1.0.6.tar.gz 15.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyodre 1.0.6
File Interpreter ABI Platform
pyodre-1.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 31.0 kB

Release files / pyodre-1.0.6.tar.gz

Download URL pyodre-1.0.6.tar.gz
Size 15.8 kB
Tags Source
SHA-256 checksum
How to use checksums
16b7f929546b2a90449fbc547a426bf2e02ad2ad7f02681daade31031a64993b
BLAKE2b-256 checksum
How to use checksums
f9364061d1b9e9bea8780a33dfe50dee5f1e70d8b9dd757a3df50182c871f20e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.4

Release files / pyodre-1.0.6-py3-none-any.whl

Download URL pyodre-1.0.6-py3-none-any.whl
Size 15.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d20c37afef57b0a818afd07bed3cba9fdd9db48179f80298c175e4a0cee8e6f4
BLAKE2b-256 checksum
How to use checksums
cd69ce6ae093e71d491f00427daa1b045a8734148a86190f17fe8a0d8dbe492a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.4

Release history Release notifications | RSS feed

This release

1.0.6 This release

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.19

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page