Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

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

To install:

  > pip install cortex-python

or from source code:

  > git clone git@github.com:CognitiveScale/cortex-python.git
  > cd cortex-python
  > pip install -e .

To install the optional components:

  > pip install cortex-python[viz]
  > pip install cortex-python[jupyter]
  > pip install cortex-python[builders]

Development

Setup

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

  > virtualenv --python=python3.6 _venv
  > source _venv/bin/activate

Install developer dependencies:

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

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

Publishing an alpha build

Suppose you want to release new functionality so it can be installed without releasing a new official version. We need to use an alpha version in PyPi.

  • we need to create and publish an alpha release:
  • get credentials to the cortex-python pypi CognitiveScale account (via lastpass)
  • run make dev.push. The alpha pre-release number (the N in X.Y.ZaN) with be determined automatically.

Contribution

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

The package documentation is built with Sphinx. To build the documentation:

> make docs

The documentation will be rendered in HTML format under the docs/_build/html directory.

Activate your virtual environment:

> source _venv/bin/activate

Setup your environment, if you have not done so:

> make dev.install 

Pre-release to staging

  1. Create and push an alpha release:
    > make dev.push
    
    This will build an alpha-tagged package.
  2. Merge develop to staging branch:
    > make stage
    
  3. In GitHub, create a pull request from staging to master.

Migration steps from cortex-client to cortex-python

The cortex-python library and its optional add-ons are replacing the cortex-client library. The new libraries are more lightweight and use-case focussed. Cortex-python may be used for development with or without the add-ons.

Uninstall the previous library (cortex-client)

To use the new Cortex libraries, cortex-python and cortex-python-builders you must uninstall the cortex-client library; cortex-client and cortex-pythoncannot be installed simultaneously in your python environment.

  > pip uninstall cortex-client

Install cortex-python

To install:

  > pip install cortex-python

To install the optional components:

  > pip install cortex-python[viz]
  > pip install cortex-python[jupyter]
  > pip install cortex-python[builders]

Import Client functionalities

The way Client functionalities can be imported has changed.

To import cortex :

> import cortex

To import ConnectionClient :

> from cortex.connection import ConnectionClient

Upload to Managed Content

Use ManagedContentClient to upload and download to your account's managed content. In cortex-client, ConnectionClient was used for these functionalities. The methods to upload and download remain the same.

To import ManagedContentClient:

> from cortex.content import ManagedContentClient

ConnectionClient can be used to save and retrieve connections.

Use Cortex magics

Cortex magics can be used only when the optional builders dependency is installed:

> %reload_ext cortex_builders

Deprecations and Removals from cortex-client

  1. The InputMessage and OutputMessage classes have been deprecated. Instead use the Message class:
> from cortex import Message
  1. ModelClient, ModelProcess and ModelRouter have been deprecated. Instead use the experiment API in the Client class to run experiments, save and retrieve your models.

  2. JobsClient has been deprecated. Instead use the action API in Client class to save or retrieve actions. Also, you can use the action in the builder class inside client class to build your actions. (Can be used only when optional dependency of builders is installed)

  3. SecretsClient has been deprecated. There is no equivalent replacement functionality in the python library, but you can manage secrets through the Cortex Vault in the Cortex Console or via the CLI cortex variables [command] [options].

  4. Message.with_payload() has been removed. This method was previously deprecated in cortex-client v5.5.4. Instead use the Client.message() method:

> from cortex import Cortex

> cortex = Cortex.client()
> message = cortex.message(payload={'value': 'hello world'})
  1. LocalExperiment.set_pipeline() has been removed. This method was previously deprecated in cortex-client v5.5.0. There is no replacement method for this functionality.

Metadata

Release files for cortex-python 1.1.0a2

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 1.1.0a2
File Size Uploaded Provenance
cortex-python-1.1.0a2.tar.gz 44.1 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 114.9 kB

Release files / cortex-python-1.1.0a2.tar.gz

Download URL cortex-python-1.1.0a2.tar.gz
Size 44.1 kB
Tags Source
SHA-256 checksum
How to use checksums
df3e2a62b03d582cf8f2d99f5d3f6d551be6058e926b02c788c492125772f14d
BLAKE2b-256 checksum
How to use checksums
46dff7732ccc34486bcd92f05548992631e56efd149beb2ce2d216671d9e352b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/20.8.0 requests-toolbelt/0.9.1 tqdm/4.36.0 CPython/2.7.14

Release files / cortex_python-1.1.0a2-py3-none-any.whl

Download URL cortex_python-1.1.0a2-py3-none-any.whl
Size 70.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c672ca19a1414574b99938136601a9ba45660844b72c131ad0361dded160f444
BLAKE2b-256 checksum
How to use checksums
e91653b9bb4f0edc5ed76b06051b881d539fb63f48e8564c0faca6987a816e09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/20.8.0 requests-toolbelt/0.9.1 tqdm/4.36.0 CPython/2.7.14

Security for cortex-python 1.1.0a2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release
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