Skip to main content

Python client library for REGDATA RPS Engine.

Project description

Quick Start Guide rps-engine-client-python

This guide explains how to install and use the rps-engine-client-python library from PyPI to interact with the REGDATA's RPS Engine API.


Install the Library

Install the latest version from PyPI using pip:

pip install rps-engine-client-python

Configure Your Environment

The library requires configuration for authentication and engine connection. You can provide this information via a settings.json file or .env file.

1. Location of the configuration file

The default location of the configuration file is the root project folder. If a dedicated folder or location is necessary, it could be applied by setting the environment variable RPS_CLIENT_CONFIG_DIR.

  • Set configuration file location:
$env:RPS_CLIENT_CONFIG_DIR = "path/to/config_folder"
  • Remove file location:
Remove-Item Env:RPS_CLIENT_CONFIG_DIR

2. Choosing source to load Rights Contexts and Processing Contexts

Choose by setting the context_source parameter when creating the engine instance:

  1. To load from JSON files (the default behavior, external_source_files must be included in the configuration file) = ContextSource.JSON.
  2. From the configuration settings (inside .env or settings.json) = ContextSource.SETTINGS.

Example:

engine = EngineFactory.get_engine(context_source=ContextSource.JSON)

3. Create the configuration file

Option A - Create a settings.json file

{
  "rps": {
    "engineHostName": "https://your-rps-engine-url",
    "identityServiceHostName": "https://your-identity-url",
    "clientId": "YOUR_CLIENT_ID",
    "clientSecret": "YOUR_CLIENT_SECRET",
    "timeout": 30
  },
  // Specify either the "external_source_files" section or the "rights_contexts" & "processing_contexts", according to the contexts source
  "external_source_files": {
    "rightsContextsFilePath": "path/to/rights_contexts.json",
    "processingContextsFilePath": "path/to/processing_contexts.json"
  },
  "rights_contexts": {
    "Admin": {
      "evidences": [
        { "name": "Role", "value": "Admin" }
      ]
    }
  },
  "processing_contexts": {
    "Protect": {
      "evidences": [
        { "name": "Action", "value": "Protect" }
      ]
    },
    "Deprotect": {
      "evidences": [
        { "name": "Action", "value": "Deprotect" }
      ]
    }
  }
}
  • Replace the URLs, clientId, and clientSecret with your actual values which are relevant to the Configuration in RPS CoreAdmin platform.
  • If you want to load rights and processing contexts from JSON files, provide the correct file paths in external_source_files.

Option B - Using .Env file with Environment Variables

rps__engineHostName="https://your-rps-engine-url"
rps__identityServiceHostName="https://your-identity-url"
rps__clientId="YOUR_CLIENT_ID"
rps__clientSecret="YOUR_CLIENT_SECRET"
rps__timeout=30

// One of the followings:
external_source_files__rightsContextsFilePath=path/to/rights_contexts.json
external_source_files__processingContextsFilePath=path/to/processing_contexts.json

// OR
rights_contexts__Admin__evidences__0__name="Role"
rights_contexts__Admin__evidences__0__value="Admin"

processing_contexts__Protect__evidences__0__name=Action
processing_contexts__Protect__evidences__0__value=Protect
processing_contexts__Deprotect__evidences__0__name=Action
processing_contexts__Deprotect__evidences__0__value=Deprotect

Create a Python Script

Write a python script that uses the library.

Below is a minimal example which uses the EngineFactory class for the engine connection, getting the contexts from a JSON file.

from Client.engine.engine_factory import EngineFactory
from Client.context_source import ContextSource
from Client.instance.rps_instance import RPSInstance
from Client.engine_context.processing_context import ProcessingContext
from Client.engine_context.rights_context import RightsContext
from Client.evidence import Evidence
from Client.value.rps_value import RPSValue

engine = EngineFactory.get_engine(context_source=ContextSource.JSON)

# Example usage
admin_rights_context = RightsContext(evidences=[Evidence(name='Role', value='Admin')])
protect_processing_context = ProcessingContext(evidences=[Evidence(name='Action', value='Protect')])

raw_first_name = RPSValue(instance=RPSInstance(className='User', propertyName='Name'), originalValue='Jonny')

request_context = engine.create_context().with_request(
    rps_values=[raw_first_name],
    rights_context=admin_rights_context,
    processing_context=protect_processing_context
)

request_context.transform_async()

print(f'Original: {raw_first_name.original}, Transformed: {raw_first_name.transformed}')
  • See the examples folder in the source repository for more advanced usage patterns.

Run Your Script

python your_script.py

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

rps_engine_client_python-1.0.3.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rps_engine_client_python-1.0.3-py3-none-any.whl (42.4 kB view details)

Uploaded Python 3

File details

Details for the file rps_engine_client_python-1.0.3.tar.gz.

File metadata

  • Download URL: rps_engine_client_python-1.0.3.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.11.9 Windows/10

File hashes

Hashes for rps_engine_client_python-1.0.3.tar.gz
Algorithm Hash digest
SHA256 0070511d3effff8bdcfe37250375e0ed54c704025e69d768c6a20bc4e0cfaa4a
MD5 f3b165160f07652e4515b9caaded1d96
BLAKE2b-256 956038a22fd7a22ad9f07104040f530e68f59c55d5dacfa17cfd9e2ca06733b7

See more details on using hashes here.

File details

Details for the file rps_engine_client_python-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for rps_engine_client_python-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 173e1747282313c2fd899e151fa70b1fc10299f163eaad48241eea972b36f2c6
MD5 058ac055bed114d528593105c72c92a0
BLAKE2b-256 0565ee4d0bd33fc1f44a9b979e8c266b93fb28e9b040a21d07020cd89b19917d

See more details on using hashes here.

Supported by

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