Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

OMF Python Library Sample

Version: 0.1.2_preview

This sample library requires Python 3.7+. You can download Python here.

About the library

The python OMF library is an introductory language-specific example of writing OMF Messages against OMF endpoints. It is intended as instructional samples only and are not for production use.

The library can be obtained by running: pip install omf_sample_library_preview

Other language libraries and samples are available on the AVEVA GitHub Organization.

Testing

The library is tested using PyTest. To test locally, make sure that PyTest is installed, then navigate to the Tests directory and run the test classes by executing

python -m pytest {testclass} 

where {testclass} is the name of a test class, for example ./test_omfclient.py.

Optionally to run end to end tests, rename the appsettings.placeholder.json file to appsettings.json and populate the fields, (This file is included in the gitignore and will not be pushed to a remote repository), then run

python -m pytest {testclass} --e2e True

Logging

Every request made by the library is logged using the standard Python logging library. If the client application using the library creates a logger, then library will log to it at the following levels:

Level Usage
Error any non 200-level response code, along with the error message
Info all request urls and verbs
all response status codes
Debug data payload and all request headers (Authorization header value redacted)
response content and all response headers

The process for creating a logger is described in the Logging HOWTO documentation.

An example walkthrough is shown here:

Logger Creation Example

To initiate logging, the client must create a logger, defining a log file, a desired log level, and default formatting:

    # Step 0 - set up logger
    log_file = 'logfile.txt'
    log_level = logging.INFO
    logging.basicConfig(filename=log_file, encoding='utf-8', level=log_level, datefmt='%Y-%m-%d %H:%M:%S',
                    format='%(asctime)s %(module)16s,line: %(lineno)4d %(levelname)8s | %(message)s')

This creates a logger object that streams any logged messages to the desired output. The libraries called by the client, including this ADH Sample Library Python, that have implemented logging will send their messages to this logger automatically.

The log level specified will result in any log at that level or higher to be logged. For example, INFO captures INFO, WARNING, ERROR, and CRITICAL, but ignores DEBUG.

Logger Usage Example

To change the log level after creation, the level can be set using the following command

logging.getLogger().setLevel(logging.DEBUG)

This concept is particularly helpful when debugging a specific call within the application. Logging can be changed before and after a call to the library in order to provide debug logs for that specific call only, without flooding the logs with debug entries for every other call to the library.

An example of this can be seen here.

    # Step 4 - Retrieve the data view
    original_level = logging.getLogger().level
    logging.getLogger().setLevel(logging.DEBUG)

    container_service.createContainers(omf_containers)

    logging.getLogger().setLevel(original_level)

Note that the original level was recorded, logging was set to debug, the createContainers call was performed, then logging was set to its previous level. The logs will contain debug message for only this call, and all other calls before and after will be logged with their original level.


Developed using Python 3.10.1

For the main AVEVA samples page ReadMe

Metadata

Release files for omf-sample-library-preview 0.1.2rc0

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

Source distribution (sdist)

Source distribution for omf-sample-library-preview 0.1.2rc0
File Size Uploaded Provenance
omf_sample_library_preview-0.1.2rc0.tar.gz 17.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for omf-sample-library-preview 0.1.2rc0
File Interpreter ABI Platform
omf_sample_library_preview-0.1.2rc0-py3-none-any.whl Python 3 none any Details

Total release size: 50.7 kB

Release files / omf_sample_library_preview-0.1.2rc0.tar.gz

Download URL omf_sample_library_preview-0.1.2rc0.tar.gz
Size 17.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f4e968c99ac85eea67e856745d8edc4bed43198ba66a6f33415c950f21ed6f85
BLAKE2b-256 checksum
How to use checksums
c975275df62f402409448dfb7fa072afe58761a7b5ee3dfbc0ad95828b4c58e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.5

Release files / omf_sample_library_preview-0.1.2rc0-py3-none-any.whl

Download URL omf_sample_library_preview-0.1.2rc0-py3-none-any.whl
Size 33.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
28c2bca6f3a3cc4b774c7f2d7f95804e34960301dfa0a574ffac9aeea4984b8c
BLAKE2b-256 checksum
How to use checksums
0ea26553750cb067cb7e4910b97194a0611bf0c246d600b02780a2cea4ebc887
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.5

Security for omf-sample-library-preview 0.1.2rc0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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