Python module for the CognitiveScale Cortex Cognitive Platform
Project description
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:
- Developer guide: https://docs.cortex.insights.ai/docs/developer-guide/overview/
- Cortex Python references: https://docs.cortex.insights.ai/docs/developer-guide/reference-guides
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
- Run unit tests via
make test
- Manually verification (i.e. try the new changes out in Cortex) to make sure everything is going well. Not required, but highly encouraged.
- Bump up
setup.py
version and update theCHANGELOG.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
- Create and push an alpha release:
This will build an alpha-tagged package.> make dev.push
- Merge
develop
tostaging
branch:> make stage
- In GitHub, create a pull request from
staging
tomaster
.
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-python
cannot 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
- The
InputMessage
andOutputMessage
classes have been deprecated. Instead use theMessage
class:
> from cortex import Message
-
ModelClient
,ModelProcess
andModelRouter
have been deprecated. Instead use theexperiment
API in theClient
class to run experiments, save and retrieve your models. -
JobsClient
has been deprecated. Instead use theaction
API inClient
class to save or retrieve actions. Also, you can use theaction
in the builder class inside client class to build your actions. (Can be used only when optional dependency of builders is installed) -
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 CLIcortex variables [command] [options]
. -
Message.with_payload()
has been removed. This method was previously deprecated incortex-client
v5.5.4. Instead use theClient.message()
method:
> from cortex import Cortex
> cortex = Cortex.client()
> message = cortex.message(payload={'value': 'hello world'})
-
LocalExperiment.set_pipeline()
has been removed. This method was previously deprecated incortex-client
v5.5.0. There is no replacement method for this functionality. -
The
cortex-python
package depends on less libraries thancortex-client
. Users of the cortex-client that have incrementally upgraded to different versions of the cortex-client package in the same environment are likely to have downloaded the following transitive dependencies. When cortex-python is used in place of cortex-client, these transitive dependencies will no longer be included. Accordingly, users that depend on any of the transitive dependencies must explicitly install them. The list of these transitive dependencies includes:
Flask==1.0.2
discovery-transitioning-utils>=1.3.50
diskcache>=3.0.5,<3.1
ipython>=6.4.0
matplotlib>=2.2.2
maya==0.5.0
scikit-learn>=0.20.0
seaborn>=0.9.0
tenacity==5.0.2
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for cortex_python-1.4.0a2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb90ba0d991de4f81790ef15ca8d8375fca8db246c2bc47d97806051a076386e |
|
MD5 | 8df91b749ab8f28cb8cd54e56fa751a6 |
|
BLAKE2b-256 | 9ce03cadc83938665501bb746a9803867e30bac3f29ff8ac4637abec7ab4ef5c |