Skip to main content

Open Digital Rights Enforcement Framework python implementation

Project description

ODRE Framework

Quickstart

To enforce an ODRL policy using the Python Interpreter

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)

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 unsupported
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 unsupported
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

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyodre-0.0.11.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

pyodre-0.0.11-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file pyodre-0.0.11.tar.gz.

File metadata

  • Download URL: pyodre-0.0.11.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.4

File hashes

Hashes for pyodre-0.0.11.tar.gz
Algorithm Hash digest
SHA256 b37cac396c51380967219bf03c277fdd72ab6f7f14428ac6235e011b7908ff57
MD5 4cc9e4d8247bdb7f96e932cb7c1d3c8b
BLAKE2b-256 6d32bc81d9881d88465d25a5df3056786c6b77b9ef63479c07d2ebe7c5d76fe5

See more details on using hashes here.

Provenance

File details

Details for the file pyodre-0.0.11-py3-none-any.whl.

File metadata

  • Download URL: pyodre-0.0.11-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.4

File hashes

Hashes for pyodre-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 b1d4e1ca54f6ee0c5f13ba4b5cf1079d889f7c1a422d8cd4af6a94445f8d986c
MD5 7e2981a037682d40c47db6d77ace71c4
BLAKE2b-256 fda4c00a5f502753b1d5c1ced68f21f4b3ce9af0b7eda556663a282692a1dc6f

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page