Skip to main content

A preview of an ADH (Aveva Data Hub) client library

Project description

AVEVA Data Hub Python Library Sample

:loudspeaker: Notice: This library is an AVEVA Data Hub targeted version of the ocs_sample_library_preview. The ocs_sample_library_preview library is being deprecated and this library should be used moving forward.

Version: 0.9.2_preview

Build Status

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

  • NOTE: The library previously required Python 3.9+ to take advantage of type annotations. To provide compatibility with environments that cannot upgrade Python to 3.9, from __future__ import annotations was added to each necessary file. This provides backwards compatibility down to Python 3.7.

About the library

The python ADH library is an introductory language-specific example of programming against Aveva Data Hub (ADH). It is intended as instructional samples only and are not for production use. The samples also work on OSIsoft Cloud Services unless otherwise noted.

They can be obtained by running: pip install adh_sample_library_preview

The library is not intended to show every endpoint and every option/parameter for endpoints it has. The library is known to be incomplete.

Other language libraries and samples are available on GitHub.

Tests are done by testing the sample apps that use this.

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)

    dataview = adh_client.DataViews.getDataView(
        namespace_id, SAMPLE_DATAVIEW_ID)

    logging.getLogger().setLevel(original_level)

Note that the original level was recorded, logging was set to debug, the getDataView 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.9.5.

AVEVA Samples are licensed under the Apache 2 license.

For the main ADH sample libraries page ReadMe
For the main ADH samples page ReadMe
For the main AVEVA samples page ReadMe

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

adh_sample_library_preview-0.9.2rc0.tar.gz (57.5 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file adh_sample_library_preview-0.9.2rc0.tar.gz.

File metadata

File hashes

Hashes for adh_sample_library_preview-0.9.2rc0.tar.gz
Algorithm Hash digest
SHA256 2dbcaf342a3d11ae33890aa0a4f0b9f1b2f6c9ea47b5a40cc1aa758a95760d3c
MD5 ed9263963870fc01c4930e3ec64508e9
BLAKE2b-256 75c3d50b61f73dacf7c38c2c00bef6d010b68dbf03d5fda81e08512eb1886e27

See more details on using hashes here.

File details

Details for the file adh_sample_library_preview-0.9.2rc0-py3-none-any.whl.

File metadata

File hashes

Hashes for adh_sample_library_preview-0.9.2rc0-py3-none-any.whl
Algorithm Hash digest
SHA256 fecfee7a63be1a548807b0dbb28bdef7e34e910da632916bb5b21bf49255a598
MD5 077a0225018a3a23c9b8268e2bad7aed
BLAKE2b-256 465ed46235cd33636ba0201c87ec21b4436bdd1304d39857e6395651fb7adfda

See more details on using hashes here.

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