Skip to main content

Python SDK for interacting with the Chakra API, providing seamless pandas DataFrame integration

Project description

Chakra SDK

Chakra Banner

A Python SDK for interacting with the Chakra API. This SDK provides seamless integration with pandas DataFrames for data querying and manipulation.

Features

  • Token-based Authentication: Secure authentication using DB Session keys
  • Pandas Integration: Query results automatically converted to pandas DataFrames
  • Automatic Table Management: Create and update tables with schema inference
  • Batch Operations: Efficient data pushing with batched inserts

Installation

pip install chakra-py

Quick Start

from chakra_py import Chakra
import pandas as pd

# Initialize client
client = Chakra("YOUR_DB_SESSION_KEY")

# REQUIRED: Authenticate and set the token
client.login()

# Query data (returns pandas DataFrame)
df = client.execute("SELECT * FROM my_table")
print(df.head())

# Push data to a new or existing table
data = pd.DataFrame({
    "id": [1, 2, 3],
    "name": ["Alice", "Bob", "Charlie"],
    "score": [85.5, 92.0, 78.5]
})
client.push("students", data, create_if_missing=True)

Querying Data

Execute SQL queries and receive results as pandas DataFrames:

# Simple query
df = client.execute("SELECT * FROM table_name")

# Complex query with aggregations
df = client.execute("""
    SELECT 
        category,
        COUNT(*) as count,
        AVG(value) as avg_value
    FROM measurements
    GROUP BY category
    HAVING count > 10
    ORDER BY avg_value DESC
""")

# Work with results using pandas
print(df.describe())
print(df.groupby('category').agg({'value': ['mean', 'std']}))

Pushing Data

Push data from pandas DataFrames to tables with automatic schema handling:

# Create a sample DataFrame
df = pd.DataFrame({
    'id': range(1, 1001),
    'name': [f'User_{i}' for i in range(1, 1001)],
    'score': np.random.normal(75, 15, 1000).round(2),
    'active': np.random.choice([True, False], 1000)
})

# Create new table with inferred schema
client.push(
    table_name="users",
    data=df,
    create_if_missing=True  # Creates table if it doesn't exist
)

# Update existing table
new_users = pd.DataFrame({
    'id': range(1001, 1101),
    'name': [f'User_{i}' for i in range(1001, 1101)],
    'score': np.random.normal(75, 15, 100).round(2),
    'active': np.random.choice([True, False], 100)
})
client.push("users", new_users, create_if_missing=False)

The SDK automatically:

  • Infers appropriate column types from DataFrame dtypes
  • Creates tables with proper schema when needed
  • Handles NULL values and type conversions
  • Performs batch inserts for better performance

Development

To contribute to the SDK:

  1. Clone the repository
git clone https://github.com/Chakra-Network/python-sdk.git
cd chakra-sdk
  1. Install development dependencies with Poetry
# Install Poetry if you haven't already
curl -sSL https://install.python-poetry.org | python3 -

# Install dependencies
poetry install
  1. Run tests
poetry run pytest
  1. Build package
poetry build

PyPI Publication

The package is configured for easy PyPI publication:

  1. Update version in pyproject.toml
  2. Build distribution: poetry build
  3. Publish: poetry publish

License

MIT License - see LICENSE file for details.

Support

For support and questions, please open an issue in 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

chakra_py-1.0.3.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

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

chakra_py-1.0.3-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file chakra_py-1.0.3.tar.gz.

File metadata

  • Download URL: chakra_py-1.0.3.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.11.3 Darwin/23.5.0

File hashes

Hashes for chakra_py-1.0.3.tar.gz
Algorithm Hash digest
SHA256 568f7bd7a5493ac3461569fcaa10f9f588e0206d0ed7d101d755c65753f1ce82
MD5 30dddb5afa35d1193539c2a3cf8ac231
BLAKE2b-256 bf1d5d22fcc98cf85340fcc96f84fce2e5ded99dbb36b90604811eee177c81d9

See more details on using hashes here.

File details

Details for the file chakra_py-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: chakra_py-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.11.3 Darwin/23.5.0

File hashes

Hashes for chakra_py-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6a61d9fb4af407327df7eb940e860d23e1556fb713c989a27120b12e381b9666
MD5 3da99f8d43983db74f1aa10c4befb95e
BLAKE2b-256 0a777d63e61acb0dc9c4b84f368db4d16d14460c189f643e4e592aec931a4c5e

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