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 your client id and client secret to an environment variable (don't want it to be hardcoded):

    Linux (bash):

    export DATACRUNCH_CLIENT_ID=YOUR_ID_HERE
    export DATACRUNCH_CLIENT_SECRET=YOUR_SECRET_HERE
    
  • To enable sending inference requests from SDK you must generate an inference key - Instructions on inference authorization

  • Add your inference key to an environment variable

    Linux (bash):

    export DATACRUNCH_INFERENCE_KEY=YOUR_API_KEY_HERE
    

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

  • Example for creating a new instance:

    import os
    from datacrunch import DataCrunchClient
    
    # Get credentials from environment variables
    CLIENT_ID = os.environ.get('DATACRUNCH_CLIENT_ID')
    CLIENT_SECRET = os.environ['DATACRUNCH_CLIENT_SECRET']
    
    # 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='ubuntu-24.04-cuda-12.8-open-docker',
                                          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

Create this file in the root directory of the project:

from datacrunch.datacrunch import DataCrunchClient

CLIENT_SECRET = 'secret'
CLIENT_ID = 'your-id'

# 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 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.15.0.tar.gz (44.2 kB view details)

Uploaded Source

Built Distribution

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

datacrunch-1.15.0-py3-none-any.whl (58.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: datacrunch-1.15.0.tar.gz
  • Upload date:
  • Size: 44.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for datacrunch-1.15.0.tar.gz
Algorithm Hash digest
SHA256 a93465e43982cdd7c31bdf3cf80d9f4ac637aaf658d65f11e53b8a42c867d0f2
MD5 d9a3bacd6a9f7b292e99a1541be72e1e
BLAKE2b-256 4ebd965a50d175c384894643c6b829061d30a13427b7f886c91433cfb83717f5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: datacrunch-1.15.0-py3-none-any.whl
  • Upload date:
  • Size: 58.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for datacrunch-1.15.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ac7c6069561682279f06d43956cce7925c7c9db59264742056f632a223329f2
MD5 abcedef66deb3f8e62c605f3eb476ae6
BLAKE2b-256 286e0bbb270abe9c682431d617383bb0a7b27e7ca5e7eaaae03e5e4281595e19

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