C3 AI Documentation Home

Remote access to C3 from Python

The C3 AI Python SDK allows users to interact with the C3 AI Type System and APIs from Python. The SDK is automatically available through the C3 AI-managed JupyterLab Service and is available to Python actions and pipelines running on the C3 Server.

There are some situations where you may want to use the C3 AI Python SDK outside of these environments. For example, you may be running in the hosted Jupyter service of a cloud provider. In these cases, the platform provides remote access. A Python interpreter outside of C3 AI can authenticate with C3 AI and download on-demand the parts of the C3 AI API needed to interact with the C3 Server.

This page provides instructions on how to set up remote access to the Python SDK.

Limitations of remote access

Using remote access has some limitations compared to accessing the C3 AI Python SDK through the C3 AI-managed JupyterLab service:

  • Users need to manually set up their conda environments and authentication tokens (see below).
  • Most C3 AI methods are run on the server instead of staying in process.
  • Some built-in integrations between JupyterLab and the C3 Server are not be available
    • (For example, status indicator of server connection, or code samples).

Requirements and initial setup

To configure remote access, you need:

  1. Web access to a running C3 AI application instance. For the subsequent instructions, it is assumed that the application instance is at the URL https://mydomain/env/app, where
    • env is the application's environment name, and
    • app is the application's name.
  2. An Anaconda environment for Python 3.12 containing a small set of packages.
  3. An OAuth authentication token obtained from your application.

Assuming you have web access to a C3 application instance, the following section examines items 2 and 3.

Setting up an Anaconda Python environment for remote access

Python code requires an Anaconda environment. It should contain the following packages:

PackageVersionPackage Manager
Python3.12conda
yajl2.1.0conda
pkg-config0.29.2conda
jsonslicer0.1.7pip

Here is an example Anaconda environment YAML file for creating an environment with these packages:

YAML
name: c3-remote
channels:
  - default
  - conda-forge
dependencies:
  - python=3.12
  - yajl=2.1.0
  - pkg-config=0.29.2
  - pip
  - pip:
    - jsonslicer==0.1.7

The following table lists packages required for an Anaconda environment that works with Pandas:

PackageVersionPackage Manager
Python3.12conda
yajl2.1.0conda
pkg-config0.29.2conda
dill0.3.9conda
pyarrow19.0.0conda
scipy1.11.4conda
numpy1.26.4conda
pandas2.2.3conda
polars0.19.14conda
jsonslicer0.1.7pip

Here is an example YAML file for an Anaconda environment that works with Pandas:

YAML
name: c3-remote-data
channels:
  - default
  - conda-forge
dependencies:
  - python=3.12
  - yajl=2.1.0
  - pkg-config=0.29.2
  - dill==0.3.9
  - pyarrow==19.0.0
  - scipy==1.11.4
  - numpy=1.26.4
  - pandas=2.2.3
  - polars==0.19.14
  - pip
  - pip:
    - jsonslicer==0.1.7

How to obtain an OAuth authentication token

The C3 Agentic AI Platform integrates OAuth to ensure secure data access and interactions. It provides tools and configurations to set up and manage OAuth-based authentication seamlessly.

To learn how to obtain an access token, see Generate an Access Token.

Initializing remote access in a Python session

To use remote access, first start a Python interpreter in the Anaconda environment that you created using the instructions above. If you are using JupyterLab, you may need to install a Jupyter kernel based on this environment.

In your Python interpreter session, define the function load_c3 as follows:

Python
def load_c3(app_url, auth):
    from urllib.request import urlopen
    src = urlopen(app_url + '/remote/c3.py').read()
    exec_scope = {}
    exec(src, exec_scope)
    return exec_scope["get_c3"](url=app_url, authz=auth)

c3 = load_c3(app_url, auth)

Next, call this function and assign it to the variable c3:

Python
c3 = load_c3(APP_URL, AUTH_STRING)

where APP_URL is the URL of your application (of the form https://domain/env/app), and AUTH_STRING is the OAuth authentication token you obtained from the JavaScript console.

Now, you can access C3 AI APIs through this c3 variable.

Python
c3.pkg().name()
>>> 'windTurbine'

See also

Was this page helpful?