Skip to main content

Python package to interact with Relatics v5 webservices

Project description

PyRelatics2

PyPI Python version PyPI version PyPI status Apache-2.0 license GitHub branch check state GitHub branch check state

Python package to interact with Relatics v5 webservices.

This package allows you to interact with Relatics v5 webservices in two ways:

  • Get data from a "Servers for providing data" webservice.
  • Submit data to a "Servers for receiving data" webservice.

Three authentication methods are supported: "OAuth 2.0 - Client credentials", "Entry code" and "Unauthenticated".

Setting up

from pyrelatics2 import RelaticsWebservices

client = RelaticsWebservices("company_subdomain", "workspace_id")

When using "OAuth 2.0 - Client credentials", the client credentials can be stored in a dedicated class instance for later use.

from pyrelatics2 import ClientCredential

cc = ClientCredential(client_id="client_id", client_secret="client_secret")

Example of getting data

Getting data with "OAuth 2.0 - Client credentials":

from pyrelatics2 import ClientCredential, RelaticsWebservices

cc = ClientCredential(client_id="client_id", client_secret="client_secret")
client = RelaticsWebservices("company_subdomain", "workspace_id")

# Optionally prepare a dictionary of parameters
parameters = {
    "sample_parameter_name_1": "sample_parameter_value_1",
    "sample_parameter_name_2": "sample_parameter_value_2",
}

client.get_result(operation_name="sample_operation", parameters=parameters, authentication=cc)

Other forms of authentication can also be used:

from pyrelatics2 import RelaticsWebservices

client = RelaticsWebservices("company_subdomain", "workspace_id")

# Authentication via entry code
entry_code = "sample_entry_code"
client.get_result(operation_name="sample_operation", parameters=None, authentication=entry_code)

# No authentication
client.get_result(operation_name="sample_operation", parameters=None, authentication=None)

Example of sending data

Sending data with "OAuth 2.0 - Client credentials", with data as list:

from pyrelatics2 import ClientCredential, RelaticsWebservices

cc = ClientCredential(client_id="client_id", client_secret="client_secret")
client = RelaticsWebservices("company_subdomain", "workspace_id")

# Prepare the data to be send
data = [
    {"name": "test name 1", "description": "test description 1"},
    {"name": "test name 2", "description": "test description 2"},
]

client.run_import(operation_name="sample_operation", data=data, authentication=cc)

Again, other forms of authentication can also be used:

from pyrelatics2 import RelaticsWebservices

client = RelaticsWebservices("company_subdomain", "workspace_id")
data = [{"name": "test 1", "description": "desc 1"},{"name": "test 2", "description": "desc 2"}]

# Authentication via entry code
entry_code = "sample_entry_code"
client.run_import(operation_name="sample_operation", data=data, authentication=entry_code)

# No authentication
client.run_import(operation_name="sample_operation", data=data, authentication=None)

Example of sending data and documents

It is possible to include documents as part of the upload, as described in Use import for uploading files. Simply add list of the filepaths to be included.

from pyrelatics2 import ClientCredential, RelaticsWebservices

cc = ClientCredential(client_id="client_id", client_secret="client_secret")
client = RelaticsWebservices("company_subdomain", "workspace_id")

# Prepare the data and documents to be send
data = [
    {"name": "test name 1", "description": "test description 1", "reference": "file_a.jpg"},
    {"name": "test name 2", "description": "test description 2", "reference": "file_b.jpg"},
]
documents=[
    "sample-data\\file_a.jpg",
    "sample-data\\file_b.jpg",
]

client.run_import(operation_name="sample_operation", data=data, authentication=cc, documents=documents)

Example of sending data from a file

Instead of supplying the data with a list, it is possible to give the filepath of a supported file type. Supported file type are defined in Supported file types for import as "MS Excel, XML and comma-separated ASCII". The code will except these file extensions: xlsx, xlsm, xlsb, xls or csv.

from pyrelatics2 import ClientCredential, RelaticsWebservices

cc = ClientCredential(client_id="client_id", client_secret="client_secret")
client = RelaticsWebservices("company_subdomain", "workspace_id")

# Prepare the data and documents to be send
data = "sample-data\\sample_data.xlsx"

client.run_import(operation_name="sample_operation", data=data, authentication=cc)

Result of get_result()

The raw response of an export will be processed into a ExportResult object [^1]. When an error was registered, it will become Falsly for easy checking. The ExportResult object will contain any documents that were part of the response. They will be extracted from the raw base64 encoded zipfile in the original response, into a dict.

Result of run_import()

The raw response of an import will be processed into a ImportResult object [^1]. When an error was registered, it will become Falsly for easy checking. The ImportResult object will contain all the messages, including properties to easily retrieve them by their status (Progress, Comment, Success, Warning, Error).

The ImportResult object also includes all the updated that Relatics made to instances. They contain their ID and possible ForeignKey. Properties are available to easily retrieve them by their action (Add, Update).

When the ImportResult object is print(), it will display a formatted and human presentable outcome of the import process.

Exceptions

In addition to basic Exceptions, there is a custom exceptions the code will raise:

  • TokenRequestError: When the token for a "OAuth 2.0 - Client credentials" authentication could not be retrieved.

Logging

This package uses the standard Python logging functionality. Logging can be activated with:

import logging

LOG_FORMAT = "%(asctime)s %(name)s %(levelname)s %(message)s"  # Define a custom log format
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)

logging.getLogger("pyrelatics2.client").setLevel(logging.DEBUG)

Logging is available in these modules for debugging purpose: pyrelatics2.client, pyrelatics2.exceptions and pyrelatics2.result_classes.

[^1]: Parsing of the raw response can be turned off via the auto_parse_response=false argument. In that case the method will return the raw response in the form of a suds.sudsobject.Object

Development

To install this package for development, use this command in your venv:

pip install -e ".[dev]"

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

pyrelatics2-1.0.0a0.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

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

pyrelatics2-1.0.0a0-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file pyrelatics2-1.0.0a0.tar.gz.

File metadata

  • Download URL: pyrelatics2-1.0.0a0.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyrelatics2-1.0.0a0.tar.gz
Algorithm Hash digest
SHA256 a09f10123e020e32fb6a0eaaa208c0d7999a34a5000d7ec7dfd7def59fff4693
MD5 209d4e9a8ce699842581dff6a516823b
BLAKE2b-256 33434f0c97d4716c48d8a3d547675e26bbb1ad9e8f2459d854436d1358b687d4

See more details on using hashes here.

File details

Details for the file pyrelatics2-1.0.0a0-py3-none-any.whl.

File metadata

  • Download URL: pyrelatics2-1.0.0a0-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyrelatics2-1.0.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 e587ce19f48cb1c4736c25d4d6d317c17e9bb196b302a238e04b33e6113f04cb
MD5 8e57a289d465f273f803444829b36a70
BLAKE2b-256 0cf55c828c0f76e02a7c2858b95d1d8eb2e3288b477a2c5d1c8e7866dde8f2e4

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