Skip to main content

A Python SDK for Omni API

Project description

omni-python-sdk

Python SDK for interacting with the Omni API

Installation

pip install -r requirements.txt

Usage

from omni_python_sdk import OmniAPI

# Set your API key and base URL
api_key = "your_api_key"
base_url = "https://your_domain.omniapp.co"
#these can optionally be set in an .env file with the following keys:
# OMNI_API_KEY=<<your api key>>
# OMNI_BASE_URL=<<your base url>>

# Define your query
query = {
    "query": {
        "sorts": [
            {
                "column_name": "order_items.created_at[date]",
                "sort_descending": False
            }
        ],
        "table": "order_items",
        "fields": [
            "order_items.created_at[date]",
            "order_items.sale_price_sum"
        ],
        "modelId": "your_model_id",
        "join_paths_from_topic_name": "order_items"
    }
}

# Initialize the API with your credentials
api = OmniAPI(api_key, base_url)
# if you've optionally set your keys in a .env file no arguments are required:
# api = OmniAPI()
# if your environment variables are stored in an alternative location
# api = OmniAPI(env_file='<<path_to_custom_env>>')

# Run the query and get a table
table = api.run_query_blocking(query)

# Convert the table to a Pandas DataFrame
df = table.to_pandas()

# Display the first few rows of the DataFrame
print(df.head())

To run the example, you need to replace your_api_key, your_domain, and your_model_id with your own values.

To get a query object, you can use the Inspector on a Omni Workbook. The query object is a JSON object that represents the query you want to run. You can find the Inspector in the View menu on a Workbook. Look for the "Query Structure" section.

For a simple command line interface, you can run the following command:

python3 examples/query.py OMNI_API_KEY https://OMNI_URL '{"query": {"sorts": [{"column_name": "omni_dbt__order_items.created_at[date]", "sort_descending": false}], "table": "omni_dbt__order_items", "fields": ["omni_dbt__order_items.created_at[date]", "omni_dbt__order_items.total_sale_price"], "modelId": "OMNI_MODEL_ID", "join_paths_from_topic_name": "order_items"}}

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

omni_python_sdk-0.1.11.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

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

omni_python_sdk-0.1.11-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file omni_python_sdk-0.1.11.tar.gz.

File metadata

  • Download URL: omni_python_sdk-0.1.11.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for omni_python_sdk-0.1.11.tar.gz
Algorithm Hash digest
SHA256 64a16fdcfc6aa7da4574b2e0b9a287bb81e79a1dfc6212dbba854da694887a22
MD5 104f1273aa738a58dd9f6ef6091bf577
BLAKE2b-256 b6832067a9ee66c7190ab80da1431d05ee96eb38611d4a4b952ac4c3b0fb85cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for omni_python_sdk-0.1.11.tar.gz:

Publisher: python-publish.yml on exploreomni/omni-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file omni_python_sdk-0.1.11-py3-none-any.whl.

File metadata

File hashes

Hashes for omni_python_sdk-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 9514cc1a872181f0f5ce87a562238e103b8c92ee5fd12357a3cafb76cff7723c
MD5 45c6a682581315490da797dbfc24735d
BLAKE2b-256 8de347557fe1dcfa6961dc12b2ce763383627f3ac77ac3952fb676bc63ece9b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for omni_python_sdk-0.1.11-py3-none-any.whl:

Publisher: python-publish.yml on exploreomni/omni-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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