Skip to main content

Python Module for the Cortex Cognitive Platform

The Cortex Python module provides an API client library to easily integrate with the Cortex Cognitive Platform. Refer to the Cortex documentation for details on how to use the library:

Installation

There are several installation options available:

  • base library - for interacting with a Sensa cluster or developing skills
poetry add cortex-python
  • model development - for feature and model developing within jupyter notebooks
poetry add cortex-python[model_development]
  • model development extras - for developing model training and inference skills
poetry add cortex-python[model_runtime]
  • Certifai Evaluator plugin - this must be installed with on of the model* extras NOTE: extra config needed to access the Sensa python repository
poetry config http-basic.sensa <USER> <TOKEN> 
poetry add cortex-python[model_development,certifai]

Install from source

git clone git@github.com:CognitiveScale/cortex-python.git
cd cortex-python
# Needed for certifai components
poetry config http-basic.sensa <USER> <TOKEN> 
poetry install

Development

Setup

When developing, it's a best practice to work in a virtual environment. Create and activate a virtual environment:

poetry install
poetry shell

Install developer dependencies:

git clone git@github.com:CognitiveScale/cortex-python.git
cd cortex-python
make dev.install

Run Developer test and linting tasks: Three types of checks are configured for this:

  1. symilar - to test code duplication
  2. pylint - for linting
  3. pytest - for running the unit tests. These are orchestrated through tox. The tox configuration is available at tox.ini

There's a convenience Makefile that has commands to common tasks, such as build, test, etc. Use it!

Testing

Unit Tests

Follow above setup instructions (making sure to be in the virtual environment and having the necessary dependencies)

  • make test to run test suite

To run an individual file or class method, use pytest. Example tests shown below:

  • file: pytest test/unit/agent_test.py
  • class method: pytest test/unit/agent_test.py::TestAgent::test_get_agent

Pre-release to staging

Note: this repository using git tag for versionning

  1. Create and push an alpha release:
git tag -a 6.5.0a<N> -m 'alpha tag'
git push --tags
make dev.push
This will build an alpha-tagged package.
  1. Merge develop to staging branch:
make stage
  1. In GitHub, create a pull request from staging to master.
git tag -a 6.5.0 -m 'rlease tag'
git push --tags

Contributing

After contributing to the library, and before you submit changes as a PR, please do the following

  1. Run unit tests via make test
  2. Manually verification (i.e. try the new changes out in Cortex) to make sure everything is going well. Not required, but highly encouraged.
  3. Bump up setup.py version and update the CHANGELOG.md

Documentation

Activate your virtual environment:

poetry shell

Set up your environment, if you have not done so:

make dev.install 

The package documentation is built with Sphinx and generates versioned documentation for all tag matching the release/X.Y.Z pattern and for the master branch. To build the documentation:

make docs.multi

The documentation will be rendered in HTML format under the docs/_build/${VERSION} directory.

Configuring the client

There are four mechanisms for configuring a client connection.

  1. Use $HOME/.cortex/config file setup via cortex configure.

    from cortex.client import Cortex
    client=Cortex.client(verify_ssl_cert=True|False)
    
  2. Use environment variables CORTEX_URL, CORTEX_TOKEN, and CORTEX_PROJECT

    from cortex.client import Cortex
    client=Cortex.client(verify_ssl_cert=True|False)
    

This is a table of supported environment variables.

These ENV vars are injected by the Sensa RUNTIME for use during skill startup.

Environment variables Description
CORTEX_PERSONAL_ACCESS_CONFIG JSON string containing a Pesonal Access Token obtained from the console UI
CORTEX_CONFIG_DIR A folder containing the config created by the cortex configure command
CORTEX_TOKEN A JWT token generate by cortex configure token or provided during skill invokes
CORTEX_PROJECT Project used during api requests
CORTEX_URL URL for Sensa apis
  1. Use method kwargs with Cortex.client()

    from cortex.client import Cortex
    client=Cortex.client(api_endpoint="<URL>", token="<token>", project="<project>", verify_ssl_cert=True|False)
    
  2. Using the skills invoke message, this allows for authentication using the caller's identity.

    from cortex.client import Cortex
    client=Cortex.from_message({})    
    

Metadata

Release files for cortex-python 7.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cortex-python 7.0.0
File Size Uploaded
cortex_python-7.0.0.tar.gz 45.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cortex-python 7.0.0
File Interpreter ABI Platform
cortex_python-7.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 104.5 kB

Release files / cortex_python-7.0.0.tar.gz

Download URL cortex_python-7.0.0.tar.gz
Size 45.3 kB
Tags Source
SHA-256 checksum
How to use checksums
54467aa71203b342822b54f0a491f966316d51843241c55b04d329619028dc0b
BLAKE2b-256 checksum
How to use checksums
b9f8b52aff36a2bb09317c5f98872989ed5adf9f397f8e14ef74f134230c1245
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.15 Linux/4.18.0-477.15.1.el8_8.x86_64

Release files / cortex_python-7.0.0-py3-none-any.whl

Download URL cortex_python-7.0.0-py3-none-any.whl
Size 59.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f186081f989576a4c09794551da85092249c74237bc2070832881bd991ea5aff
BLAKE2b-256 checksum
How to use checksums
8b142a5d02d02b70cdc699aafad91f3b515f9463929e470a03ab57c80f93edc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.10.15 Linux/4.18.0-477.15.1.el8_8.x86_64

Release history Release notifications | RSS feed

This release

7.0.0 This release

2 release files

6.3.3

2 release files

6.3.2

2 release files

6.3.1

2 release files

6.1.0

2 release files

6.0.3

2 release files

6.0.2

2 release files

6.0.1

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.1

2 release files

1.1.0

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page