Skip to main content

Official Python SDK for DataCrunch Public API

Project description

DataCrunch Python SDK

The official DataCrunch.io Python SDK.

The SDK's documentation is available on ReadTheDocs

DataCrunch's Public API documentation is available here.

Getting Started - Using the SDK:

  • Install via pip:

    pip3 install datacrunch
    
  • Generate your client credentials - instructions in the public API docs.

  • Add the client secret to an environment variable (don't want it to be hardcoded):

    Linux (bash):

    export DATACRUNCH_CLIENT_SECRET=Z4CZq02rdwdB7ISV0k4Z2gtwAFKiyvr2U1l0KDIeYi
    

    Other platforms: https://en.wikipedia.org/wiki/Environment_variable

  • Example for creating a new instance:

    import os
    from datacrunch import DataCrunchClient
    
    # Get client secret from environment variable
    CLIENT_SECRET = os.environ['DATACRUNCH_CLIENT_SECRET']
    CLIENT_ID = 'Ibk5bdxV64lKAWOqYnvSi'
    
    # Create datcrunch client
    datacrunch = DataCrunchClient(CLIENT_ID, CLIENT_SECRET)
    
    # Get all SSH keys
    ssh_keys = datacrunch.ssh_keys.get()
    ssh_keys = list(map(lambda key: key.id, ssh_keys))
    
    # Create a new instance
    instance = datacrunch.instances.create(instance_type='1V100.6V',
                                          image='fastai',
                                          ssh_key_ids=ssh_keys,
                                          hostname='example',
                                          description='example instance')
    
    # Delete instance
    datacrunch.instances.action(instance.id, datacrunch.constants.instance_actions.DELETE)
    

    More examples can be found in the /examples folder or in the documentation.

Development

Setting up the local development environment

  • Clone the repository:

    git clone
    
  • Create local virtual environment:

    python3 -m venv datacrunch_env && source ./datacrunch_env/bin/activate
    

    or if using fish shell:

    python3 -m venv datacrunch_env && source ./datacrunch_env/bin/activate.fish
    
  • Install Dependencies:

    pip3 install -e .[test]
    pip3 install -U pytest
    

Running Tests

We use pytest for testing.

  • To execute all tests

    pytest
    
  • To execute a single test file

    pytest ./tests/unit_tests/test_file.py
    

Local Manual Testing

from datacrunch.datacrunch import DataCrunchClient

CLIENT_SECRET = 'secret'
CLIENT_ID = 'Ibk5bdxV64lKAWOqYnvSi'

# Create datcrunch client
datacrunch = DataCrunchClient(CLIENT_ID, CLIENT_SECRET, base_url='http://localhost:3001/v1')

Generating the documentation

If added a new service, create a documentation template under api/services for that service.

cd docs
make html

Style Guide

Use autopep8 for auto code formatting:

# Install
pip3 install autopep8

# Apply to an entire directory
autopep8 directory_name --recursive --in-place --pep8-passes 2000 --verbose

# Or a single file
autopep8 file.py --in-place

Contact

You can contact us here, or send a message / open an issue in the repo.

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

datacrunch-1.0.7.tar.gz (24.4 kB view details)

Uploaded Source

Built Distribution

datacrunch-1.0.7-py3-none-any.whl (36.0 kB view details)

Uploaded Python 3

File details

Details for the file datacrunch-1.0.7.tar.gz.

File metadata

  • Download URL: datacrunch-1.0.7.tar.gz
  • Upload date:
  • Size: 24.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for datacrunch-1.0.7.tar.gz
Algorithm Hash digest
SHA256 7affce1878e53d468e7c605ee37de0f462937c1be97ae74452064c4da0367a32
MD5 6329a76e37cbe158baac72982f4aab43
BLAKE2b-256 be43adb9d1f20a5679f9b10e8a12e4b4120ba0db2df33f382351fe6d07cd0633

See more details on using hashes here.

File details

Details for the file datacrunch-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: datacrunch-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 36.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for datacrunch-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 2e451d4800dd57fcf3290f5d53aed46c9e8e60fe6468309479eb697977f5b23b
MD5 99af91a01195e4522c8a71d92b12c8c2
BLAKE2b-256 96c99e3ee89c53cad15263305b3fda426e46917760dcbdbb3fd4d46a3fa590e7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page