Skip to main content

Nortech Python SDK

Project description

nortech-python

codecov

The official Python library for Nortech AI.

Table of Contents

Overview

The nortech-python library is the official Python client for interacting with the Nortech AI platform. It provides a comprehensive interface to access and manage various components of the Nortech ecosystem, including metadata, data tools, and derivers.

The Nortech class serves as the primary entry point for the library. It encapsulates the core functionalities and provides a unified interface to interact with the Nortech API. It has 3 main components:

  • Metadata: Access and manage metadata such as workspaces, assets, divisions, units, devices, and signals.
  • Datatools: Fetch and manipulate signal data, supporting both Pandas and Polars DataFrames, time window queries, and signal filtering.
  • Derivers: Create and manage derivers, which allow computation of new signals based on existing ones. This includes creating deriver schemas, deploying derivers, managing configurations, and testing locally.

The Nortech class is designed to be flexible, allowing customization of API settings such as the base URL, API key, pagination behavior, and user agent. This makes it easy to integrate the library into various environments and workflows.

Dependencies

This package relies heavily in the following packages, and it is recommended that users have basic knowledge of them:

  • Pydantic - Used for schema validation and manipulation.
  • Pandas or Polars - Used for managing signal datasets.

Installation

You can install using pip:

pip install nortech

Or if you are using poetry:

poetry add nortech

Or if you are using UV:

uv add nortech

Config

Setup your environment variables with your NortechAPI Key:

export NORTECH_API_KEY="<NORTECH_API_KEY>"

Alternatively you can create a .env file in the root directory of your project with the content:

NORTECH_API_KEY="<NORTECH_API_KEY>"

The Nortech class can also recieve all configurations during initialization.

Pagination

This feature is implemented like in the API. By default it is disabled. To enable it add the following line to your config:

NORTECH_API_IGNORE_PAGINATION=False

Listing functions, mostly present in the nortech.metadata section, have an optional PaginationOptions input object. This object has 4 fields:

  • size - Defines the maximum number of items to be returned by the function.
  • sort_by - Defines which item field should be used for sorting.
  • sort_order - Defines the sorting order, ascending or descending.
  • next_token - Used to fetch the next page. Obtained from a previous request.

These functions return a PaginatedResponse object containing 3 functions:

  • size - Number of items returned.
  • data - List of items returned.
  • next.token - Token that can be used in the PaginationOptions to fetch the next page.

PaginatedResponse also has a next_pagination_options method that returns a PaginationOptions, which can also be used to fetch the next page.

Examples

nortech.datatools

To get a DataFrame with the requested signals:

  1. Go to your Signal Search interface.
  2. Select the desired signals.
  3. Select the DataTools exported columns and copy the resulting search_json.
  4. Use the signals field and speficy a TimeWindow as in the examples bellow.
Pandas DataFrame

In order to get a pandas DataFrame use the get_df handler:

from datetime import datetime

from nortech import Nortech
from nortech.core.values.signal import SignalInput, SignalInputDict
from nortech.datatools.values.windowing import TimeWindow

# Initialize the Nortech client
nortech = Nortech()

# Define signals to download
signal1: SignalInputDict = {
    "workspace": "workspace1",
    "asset": "asset1",
    "division": "division1",
    "unit": "unit1",
    "signal": "signal1",
}
signal2 = 789  # Signal ID
signal3 = SignalInput(workspace="workspace2", asset="asset2", division="division2", unit="unit2", signal="signal2")

# Define the time window for data download
my_time_window = TimeWindow(start=datetime(2023, 1, 1), end=datetime(2023, 1, 31))

# Call the get_df function
df = nortech.datatools.pandas.get_df(
    signals=[signal1, signal2, signal3],
    time_window=my_time_window,
)

print(df.columns)
# Output
# [
#     'timestamp',
#     'workspace_1/asset_1/division_1/unit_1/signal_1',
#     'workspace_1/asset_1/division_1/unit_1/signal_2',
#     'workspace_2/asset_2/division_2/unit_2/signal_3'
# ]
Polars DataFrame

In order to get a polars DataFrame use the get_df:

from datetime import datetime

from nortech import Nortech
from nortech.core.values.signal import SignalInput, SignalInputDict
from nortech.datatools.values.windowing import TimeWindow

# Initialize the Nortech client
nortech = Nortech()

# Define signals to download
signal1: SignalInputDict = {
    "workspace": "workspace1",
    "asset": "asset1",
    "division": "division1",
    "unit": "unit1",
    "signal": "signal1",
}
signal2 = 789  # Signal ID
signal3 = SignalInput(workspace="workspace2", asset="asset2", division="division2", unit="unit2", signal="signal2")

# Define the time window for data download
my_time_window = TimeWindow(start=datetime(2023, 1, 1), end=datetime(2023, 1, 31))

# Call the get_df function
polars_df = nortech.datatools.polars.get_df(
    signals=[signal1, signal2, signal3],
    time_window=my_time_window,
)

print(polars_df.columns)
# Output:
# [
#     'timestamp',
#     'workspace_1/asset_1/division_1/unit_1/signal_1',
#     'workspace_1/asset_1/division_1/unit_1/signal_2',
#     'workspace_2/asset_2/division_2/unit_2/signal_3'
# ]
Polars LazyFrame

In order to get a polars LazyFrame use the get_lazy_df:

from datetime import datetime

from nortech import Nortech
from nortech.core.values.signal import SignalInput, SignalInputDict
from nortech.datatools.values.windowing import TimeWindow

# Initialize the Nortech client
nortech = Nortech()

# Define signals to download
signal1: SignalInputDict = {
    "workspace": "workspace1",
    "asset": "asset1",
    "division": "division1",
    "unit": "unit1",
    "signal": "signal1",
}
signal2 = 789  # Signal ID
signal3 = SignalInput(workspace="workspace2", asset="asset2", division="division2", unit="unit2", signal="signal2")

# Define the time window for data download
my_time_window = TimeWindow(start=datetime(2023, 1, 1), end=datetime(2023, 1, 31))

# Call the get_lazy_df function
lazy_polars_df = nortech.datatools.polars.get_lazy_df(
    signals=[signal1, signal2, signal3],
    time_window=my_time_window,
)

print(lazy_polars_df.columns)
# Output:
# [
#     'timestamp',
#     'workspace_1/asset_1/division_1/unit_1/signal_1',
#     'workspace_1/asset_1/division_1/unit_1/signal_2',
#     'workspace_2/asset_2/division_2/unit_2/signal_3'
# ]

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

nortech_test-0.10.7.tar.gz (34.6 kB view details)

Uploaded Source

Built Distribution

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

nortech_test-0.10.7-py3-none-any.whl (46.9 kB view details)

Uploaded Python 3

File details

Details for the file nortech_test-0.10.7.tar.gz.

File metadata

  • Download URL: nortech_test-0.10.7.tar.gz
  • Upload date:
  • Size: 34.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.21

File hashes

Hashes for nortech_test-0.10.7.tar.gz
Algorithm Hash digest
SHA256 1cc6b826d68532b68e0c9cfa39519af449281c57c3115d1a2655baee1d457382
MD5 131c2b6f7eac839282db1e6a409a9138
BLAKE2b-256 a52f41eb49818a116e1879290e3ae8d7f8cd0c71d7059f563a783cd6df58833c

See more details on using hashes here.

File details

Details for the file nortech_test-0.10.7-py3-none-any.whl.

File metadata

File hashes

Hashes for nortech_test-0.10.7-py3-none-any.whl
Algorithm Hash digest
SHA256 2b8395df18db6036d6e94d1bce4b42a3c112cd8c2535a4a6036c85441c2ca3ba
MD5 4c705a4c7f484abccd68778a9e368867
BLAKE2b-256 6132d9751f03e7bc29ca62ce1320cc73e96b6a08e6d2711345ffcd6f1f13ec24

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