Chakra Python SDK
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
Finding your DB Session Key
- Login to the Chakra Console
- Select Settings
- Navigate to the releveant database and copy the DB Session Key (not the access key or secret access key)
https://github.com/user-attachments/assets/9f1c1ab8-cb87-42a1-8627-184617bbb7d7
Quick Start
from chakra_py import Chakra
import pandas as pd
# Initialize client
client = Chakra("YOUR_DB_SESSION_KEY")
# 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:
- Clone the repository
git clone https://github.com/Chakra-Network/python-sdk.git
cd python-sdk
- Install development dependencies with Poetry
# Install Poetry if you haven't already
curl -sSL https://install.python-poetry.org | python3 -
# Install dependencies
poetry install
- Run tests
poetry run pytest
- Build package
poetry build
PyPI Publication
The package is configured for easy PyPI publication:
- Update version in
pyproject.toml - Build distribution:
poetry build - Publish:
poetry publish
License
MIT License - see LICENSE file for details.
Support
For support and questions, please open an issue in the GitHub repository.
Metadata
Release files for chakra-py 1.0.24
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| chakra_py-1.0.24.tar.gz | 10.3 kB | Without provenance | Details for chakra_py-1.0.24.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| chakra_py-1.0.24-py3-none-any.whl | Python 3 | none | any | Details for chakra_py-1.0.24-py3-none-any.whl |
Total release size: 19.7 kB
Release files / chakra_py-1.0.24.tar.gz
| Download URL | chakra_py-1.0.24.tar.gz |
|---|---|
| Size | 10.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b48c27cd679eb7a8afbd6312a43129a65b719642fbfb0482081b22e8387096fe
|
|
BLAKE2b-256 checksum How to use checksums |
b4e3f20cacf834da4081727a756ed767fd79bc7a8827f357416913efe1c8696a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.5 CPython/3.11.3 Darwin/23.5.0
|
Release files / chakra_py-1.0.24-py3-none-any.whl
| Download URL | chakra_py-1.0.24-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c6efcda6b9616283dc1afb7042ff878f0534428ddd4dac85b108ab38ae6052d8
|
|
BLAKE2b-256 checksum How to use checksums |
455a41ebd25f71c238ce13122853d29e539a32e750c583992ac95b21f92220a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.5 CPython/3.11.3 Darwin/23.5.0
|
Security for chakra-py 1.0.24
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.