Skip to main content

Python SDK for interacting with the BitsCrunch API

Project description

BitsCrunch Python SDK

The BitsCrunch Python SDK provides a simple and secure interface to interact with the BitsCrunch API. It includes functionality for signing requests, generating secure headers, and querying the network across different API versions.


Features

  • 🚀 Supports multiple API versions: /api/v1, /api/v2, and future versions.
  • 🔐 Automatic signing: Ensures secure communication with the server by signing requests.
  • 🔧 Flexible query support: Handle query parameters and request bodies seamlessly.
  • 🛠️ Built-in error handling: Provides meaningful error messages for debugging.

Installation

Install the SDK using pip:

pip install bitscrunch-sdk

Usage

1. Initialize the SDK

To begin using the SDK, you need:

  • An access key JSON file generated from the decentralization interface.
  • The desired API version (/api/v1 or /api/v2).

Example: APIv1

from bitscrunch_sdk.apiv1 import APIv1

# Load your access key
access_key_file = "access-key.json"
api_v1 = APIv1(access_key_file)

Example: APIv2

from bitscrunch_sdk.apiv2 import APIv2

# Load your access key
access_key_file = "access-key.json"
api_v2 = APIv2(access_key_file)

2. Make a Request

GET Request Example

try:
    response = api_v1.request(
        method="GET",
        path="/market/metrics",
        params={
            "currency": "usd",
            "blockchain": 1,
            "metrics": "holders",
            "time_range": "24h",
            "include_washtrade": "true",
        },
    )
    print("Response:", response)
except Exception as e:
    print("Error:", str(e))

GET Request Async Example

try:
    response = api_v1.request_async(
        method="GET",
        path="/market/metrics",
        params={
            "currency": "usd",
            "blockchain": 1,
            "metrics": "holders",
            "time_range": "24h",
            "include_washtrade": "true",
        },
    )
    print("Response:", response)
except Exception as e:
    print("Error:", str(e))

Best Practices

1. Keep Your Access Key Secure

Store your access-key.json file securely and avoid committing it to source control.

2. Reuse the SDK Instance

Avoid creating multiple SDK instances for the same API version. Reuse a single instance:

api_v1 = APIv1("access-key.json")
# Reuse `api_v1` for multiple requests

3. Handle Errors Gracefully

Use try-except blocks to manage API errors and display meaningful messages to the user.

4. Normalize Path Inputs

Always pass normalized paths (e.g., "/market/metrics"). The SDK will automatically handle leading/trailing slashes.

5. Use the Correct API Version

Ensure you're using the correct class (APIv1, APIv2, etc.) for the desired API version.


Error Handling

The SDK provides meaningful error messages for common scenarios:

Invalid Access Key

Error: Access key, base URL, and API prefix are required to initialize the SDK.

Invalid Request

Error: HTTP 400: Invalid request parameters.

Server Errors

Error: HTTP 500: Internal Server Error.

Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Submit a pull request with a clear description of your changes.

License

This SDK is licensed under the MIT License.


Support

For issues or questions, please contact support@bitscrunch.com or open an issue on the GitHub repository.

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

bitscrunch_sdk-1.0.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

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

bitscrunch_sdk-1.0.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file bitscrunch_sdk-1.0.1.tar.gz.

File metadata

  • Download URL: bitscrunch_sdk-1.0.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for bitscrunch_sdk-1.0.1.tar.gz
Algorithm Hash digest
SHA256 1c5b8ac0e0ebb4e32e4a24c2588b0f36e430ef0f40610715d5e32c6f29b3beef
MD5 cf708330ba50d7c1ad5b9d47e67bb59e
BLAKE2b-256 e3821395ab5b08dbdc4743b40fb2ab0040deedd7295defa13b60be1595d5b086

See more details on using hashes here.

File details

Details for the file bitscrunch_sdk-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: bitscrunch_sdk-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for bitscrunch_sdk-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f9093d12f3860247253d10d1712c6d19b1bbb3feb6ee1fde585c0a69e67d062d
MD5 d59f0823fb32919eb8757d0f83f83270
BLAKE2b-256 cda446873701b5fdec8ca5465022400cbded65e610bb184c6c05eca5e9a0db2f

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