Skip to main content

Itential Python SDK

Project description

ipsdk

The Itential Python SDK provides a client implementation in Python for writing scripts that can make API calls Itential Platform or Itential Automation Gateway 4.x.

Features

  • Easy API requests with automatic authentication
  • Support for OAuth and user/password login
  • Customizable connection settings
  • Centralized logging configuration

Getting started

Install ipsdk using pip:

$ pip install ipsdk

The ipsdk package provides factory functions for connecting to either Itential Platform or Itential Automation Gateway.

The platform_factory(...) function creates a connection to Itential Platform The gateway_factory(...) function creates a connection to Itential Automation Gateway

Use one of the factory functions to create a new connection to the server and send requests.

>>> import ipsdk
>>> platform = ipsdk.platform_factory(host="platform.itential.dev", user="admin@pronghorn")
>>> res = platform.get("/health/server")
>>> res
<Response [200 OK]>
>>> res.text
'{"version":"15.8.10-2023.2.44","release":"2023.2.9"...`

The above works the same for Itential Automation Gateway, simply use gateway_factory instead of platform_factory to connect to Itential Automation Gateway.

Itential Python SDK also supports using asyncio to connect to servers as well. The example below demostrates how to connect to the server using an async connections.

import asyncio
import ipsdk

async def main():
    p = ipsdk.platform_factory(
        host="platform.itential.dev",
        user="admin@pronghorn",
        want_async=True
    )

    res = await p.get("/adapters")

if __name__ == "__main__":
    asyncio.run(main())

The connection object supports the following HTTP methods:

  • GET - Sends a HTTP GET request to the server and returns the results
  • POST - Sends a HTTP POST request to the server and returns the results
  • PUT - Sends a HTTP PUT request to the server and returns the results
  • DELETE - Sends a HTTP DELETE request to the server and returns the results
  • PATCH - Sends a HTTP PATCH request to the server and returns the resutls

The following table shows the keyworkd arguments for each HTTP method:

Keyword GET POST PUT DELETE PATCH
path Required Required Required Required Required
params Optional Optional Optional Optional Optional
json Not Supported Optional Optional Not Supported Optional

The path argument specifies the relative path of the URI. This value is prepended to the base URL. The base URL for Itential Platform is <host> and the base URL for Itential Automation Gateway is <host>/api/v2.0.

The params argument accepts a dict object that is transformed into the URL query string. For example, if params={"foo": "bar"} the resulting query string would be ?foo=bar

The json argument accepts the payload to send in the requeset as JSON. This argument accepts either a list or dict object. When specified, the data will automatically be converted to a JSON string and the Content-Type and Accept headers will be set to application/json.

Configuration

Both the platform_factory and gateway_factory functions supporting configuration using keyword arguments. The table below shows the keyword arguments for each function along with their default value.

Keyword platform_factory gateway_factory
host localhost localhost
port 0 0
use_tls True True
verify True True
user admin admin@itential
password admin admin
client_id None Not Supported
client_secret None Not Supported
want_async False False

Logging

By default all logging is turned off for ipsdk. To enable logging to stdout, using the set_logging_level function.

>>> import ipsdk
>>> import logging

>>> ipsdk.set_logging_level(logging.DEBUG)

>>> gateway = ipsdk.gateway_factory(host="gateway.itential.dev")
2025-05-04 08:09:58,105: INFO: Creating new client for https://gateway.itential.dev/api/v2.0

>>> res = gateway.get("/devices")
2025-05-04 08:10:12,009: DEBUG: connect_tcp.started host='gateway.itential.dev' port=443 local_address=None timeout=5.0 socket_options=None
2025-05-04 08:10:12,076: DEBUG: connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7fcb6cdcc980>
2025-05-04 08:10:12,076: DEBUG: start_tls.started ssl_context=<ssl.SSLContext object at 0x7fcb6cf22a80> server_hostname='gateway.itential.dev' timeout=5.0
2025-05-04 08:10:12,097: DEBUG: start_tls.complete return_value=<httpcore._backends.sync.SyncStream object at 0x7fcb6cdd4910>
2025-05-04 08:10:12,097: DEBUG: send_request_headers.started request=<Request [b'POST']>
2025-05-04 08:10:12,098: DEBUG: send_request_headers.complete
2025-05-04 08:10:12,098: DEBUG: send_request_body.started request=<Request [b'POST']>
2025-05-04 08:10:12,098: DEBUG: send_request_body.complete
2025-05-04 08:10:12,098: DEBUG: receive_response_headers.started request=<Request [b'POST']>
2025-05-04 08:10:12,231: DEBUG: receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Date', b'Sun, 04 May 2025 12:10:12 GMT'), (b'Content-Type', b'application/json'), (b'Transfer-Encoding', b'chunked'), (b'Connection', b'keep-alive'), (b'Server', b'cloudflare'), (b'Last-Modified', b'2025-05-04 12:10:12.220779'), (b'Cache-Control', b'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0'), (b'Pragma', b'no-cache'), (b'Expires', b'-1'), (b'X-Frame-Options', b'DENY'), (b'X-Xss-Protection', b'1'), (b'X-Content-Type-Options', b'nosniff'), (b'Cf-Cache-Status', b'DYNAMIC'), (b'Content-Encoding', b'gzip'), (b'Set-Cookie', b'AutomationGatewayToken=NzQ3NS42MzM2NTcxMzYyNDg=; HttpOnly; Path=/'), (b'CF-RAY', b'93a7e4c1a9626abf-RDU'), (b'alt-svc', b'h3=":443"; ma=86400')])
2025-05-04 08:10:12,232: INFO: HTTP Request: POST https://gateway.itential.dev/api/v2.0/login "HTTP/1.1 200 OK"
2025-05-04 08:10:12,233: DEBUG: receive_response_body.started request=<Request [b'POST']>
2025-05-04 08:10:12,233: DEBUG: receive_response_body.complete
2025-05-04 08:10:12,233: DEBUG: response_closed.started
2025-05-04 08:10:12,233: DEBUG: response_closed.complete
2025-05-04 08:10:12,235: DEBUG: send_request_headers.started request=<Request [b'GET']>
2025-05-04 08:10:12,235: DEBUG: send_request_headers.complete
2025-05-04 08:10:12,235: DEBUG: send_request_body.started request=<Request [b'GET']>
2025-05-04 08:10:12,235: DEBUG: send_request_body.complete
2025-05-04 08:10:12,236: DEBUG: receive_response_headers.started request=<Request [b'GET']>
2025-05-04 08:10:12,264: DEBUG: receive_response_headers.complete return_value=(b'HTTP/1.1', 200, b'OK', [(b'Date', b'Sun, 04 May 2025 12:10:12 GMT'), (b'Content-Type', b'application/json'), (b'Transfer-Encoding', b'chunked'), (b'Connection', b'keep-alive'), (b'Server', b'cloudflare'), (b'Last-Modified', b'2025-05-04 12:10:12.253899'), (b'Cache-Control', b'no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0'), (b'Pragma', b'no-cache'), (b'Expires', b'-1'), (b'X-Frame-Options', b'DENY'), (b'X-Xss-Protection', b'1'), (b'X-Content-Type-Options', b'nosniff'), (b'Cf-Cache-Status', b'DYNAMIC'), (b'Content-Encoding', b'gzip'), (b'CF-RAY', b'93a7e4c279e36abf-RDU'), (b'alt-svc', b'h3=":443"; ma=86400')])
2025-05-04 08:10:12,264: INFO: HTTP Request: GET https://gateway.itential.dev/api/v2.0/devices "HTTP/1.1 200 OK"
2025-05-04 08:10:12,264: DEBUG: receive_response_body.started request=<Request [b'GET']>
2025-05-04 08:10:12,264: DEBUG: receive_response_body.complete
2025-05-04 08:10:12,264: DEBUG: response_closed.started
2025-05-04 08:10:12,265: DEBUG: response_closed.complete

>>> print(res)
<Response [200 OK]>

License

This project is licensed under the GPLv3 open source license. See license

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

ipsdk-0.1.0.tar.gz (62.3 kB view details)

Uploaded Source

Built Distribution

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

ipsdk-0.1.0-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

Details for the file ipsdk-0.1.0.tar.gz.

File metadata

  • Download URL: ipsdk-0.1.0.tar.gz
  • Upload date:
  • Size: 62.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for ipsdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 53180a2b261da574d697414d435791969cdf5cdc2d561de26b613e4857d77b15
MD5 217b35b522063bca19de5642bba9410d
BLAKE2b-256 75c2f533c7cb400ce3c0d3841b92d708e1fd799158e63381f43585c99b56c672

See more details on using hashes here.

File details

Details for the file ipsdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ipsdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for ipsdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 45a152b830f7895559973db16f95db83b422f4e3978696420c8a90c4ba5ab4dd
MD5 0709c0bccca23233b84237184356b4ea
BLAKE2b-256 2ea2723a5c78f80e3b094fa1bbd21cf4c6f21c4a00778d82c6f4197206c409fa

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