Skip to main content

Crux Informatics API client library

Project description

Crux Python Client

A Python library for interacting with the Crux platform.

The aim of this module is to be a Pythonic way to use the Crux API reliably. It covers client functionality including scanning subscriptions, getting delivery status, and downloading files.

Python 3.6+ is supported.

See crux-python.cruxinformatics.com for detailed documentation.

Installation

Install a recent version of Python, and a Python dependency and virtual environment manager like pipenv. On macOS run:

brew install python
brew install pipenv

Install crux from PyPI in a virtual environment, and get a shell in that environment:

mkdir -p crux_example
cd crux_example
pipenv install "crux==1.4"
pipenv shell

Getting Started

Create a file, like example.py, and use the crux module:

from crux import Crux

conn = Crux()
identity = conn.whoami()
print("I am", identity.email)

Run the script:

HISTCONTROL=ignoreboth
 export CRUX_API_KEY='YOUR_API_KEY'
python3 example.py

See the installation and authentication documentation for details.

Development

Python 3.7 is required for development, which can be installed with brew install python. For heavy development work, every supported version of Python must be installed, see the pyenv documentation below.

Pipenv should be used to manage dependancies during development.

  1. Install Pipenv, on macOS run brew install pipenv
  2. git clone https://github.com/cruxinformatics/crux-python.git
  3. cd crux-python
  4. pipenv install --dev to install the dependancies
  5. pipenv shell to get a shell in the virtual environment

Multiple Python versions

To be able to run tests against all supported Python versions, you must have all supported Python versions installed. The test runner will look for binaries called python2.7, python3.5, python3.6, etc. There are multiple ways to install Python versions, we'll document using pyenv.

  1. brew install pyenv to install

  2. Put eval "$(pyenv init -)" towards the end of the shell configuration file (~/.bashrc or ~/.bash_profile), because it manipulates $PATH, for example:

    echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bashrc
    
  3. Open a new Terminal to get an updated shell

  4. Install required/missing Python versions (this assumes you have Python 2.7 already installed, otherwise install it too):

    pyenv install 3.5.6
    pyenv install 3.6.6
    pyenv install 3.7.0
    
  5. pyenv global system 3.5.6 3.6.6 3.7.0 to make all the Python versions available

  6. If you already have pipenv virtual environment, remove it with pipenv --rm so it detects the Python versions

  7. pipenv install --dev to install all the dependancies

  8. pipenv shell to get a shell in the virtual environment

Running tests

We use Nox to automate running tests, and use make to automate running some commands. These commands should be run within a shell created with pipenv shell.

# Run all tests: lint, unit, format_check
make test
# Or
nox

# Run only lint checks
make lint
# Or
nox -s lint

# Run unit tests against all available Python versions
make unit
# Or
nox -s unit

# Run integration tests agains all available Python versions
 export CRUX_API_KEY="12345"
export CRUX_API_HOST="https://api.example.com"
make integration
# Or
 export CRUX_API_KEY="12345"
export CRUX_API_HOST="https://api.example.com"
nox --s integration

# Check formatting
make format_check
# Or
nox -s format_check

# List all commands available
make
# Or
nox -l

# Run unit test only against Python 3.7
nox -s unit-3.7

# Reformat code
make format

# Generate Sphinx HTML documentation
make docs

Running test scripts

Manual testing scripts could be found at tests/regression. In order to run one, i.e. client.py, follow the steps:

  1. copy corresponding .env.dist file as .env file (if you plan to run client.py, copy client.env.dist as client.env)
  2. fill variables within .env file
  3. launch the script (while being in the tests/regression folder, execute python client.py)

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

crux-1.4.tar.gz (32.1 kB view details)

Uploaded Source

Built Distribution

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

crux-1.4-py3-none-any.whl (37.2 kB view details)

Uploaded Python 3

File details

Details for the file crux-1.4.tar.gz.

File metadata

  • Download URL: crux-1.4.tar.gz
  • Upload date:
  • Size: 32.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for crux-1.4.tar.gz
Algorithm Hash digest
SHA256 0e2157c3075ab9fd1bfe2e6f7d0a19cf17adfc2298b5413c3da704c6addecd42
MD5 7324863751cc7b3e14d5c5dbcd03211f
BLAKE2b-256 b61a1e0be0e999a83e71d31587a2105b5cda4bbacba2544570a22b19fafef8aa

See more details on using hashes here.

File details

Details for the file crux-1.4-py3-none-any.whl.

File metadata

  • Download URL: crux-1.4-py3-none-any.whl
  • Upload date:
  • Size: 37.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for crux-1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1a8bc3e965cd65a299f0c8f10d547dac410652f799ca71b7f0bdde324e4dac2d
MD5 aec6ab25b70bc3e66f7c1db84fe7ac6c
BLAKE2b-256 411b4f29ce623c1b8699f000eae09b6f813e8a68fcef5d8084adf8306c5b87ec

See more details on using hashes here.

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