# Chakra SDK
![Chakra Banner](https://github.com/Chakra-Network/python-sdk/blob/8c0b9c94a889562e7c9010e4d8bbc6894c1653ae/banner.png?raw=True)
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
```bash
pip install chakra-py
```
## Quick Start
```python
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:
```python
# 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:
```python
# 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
```bash
git clone https://github.com/Chakra-Network/python-sdk.git
cd chakra-sdk
```
2. Install development dependencies with Poetry
```bash
# Install Poetry if you haven't already
curl -sSL https://install.python-poetry.org | python3 -
# Install dependencies
poetry install
```
3. Run tests
```bash
poetry run pytest
```
4. Build package
```bash
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.
Raw data
{
"_id": null,
"home_page": "https://github.com/Chakra-Network/python-sdk",
"name": "chakra-py",
"maintainer": null,
"docs_url": null,
"requires_python": "<3.13,>=3.9",
"maintainer_email": null,
"keywords": "chakra, sdk, api, data, pandas, dataframe, database",
"author": "Chakra Labs Team",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/66/fc/381ca1e570d898dd8a8c07bc798c521ec26797a51fa257a2b9dd15d9ed78/chakra_py-1.0.6.tar.gz",
"platform": null,
"description": "# Chakra SDK\n\n![Chakra Banner](https://github.com/Chakra-Network/python-sdk/blob/8c0b9c94a889562e7c9010e4d8bbc6894c1653ae/banner.png?raw=True)\n\nA Python SDK for interacting with the Chakra API. This SDK provides seamless integration with pandas DataFrames for data querying and manipulation.\n\n## Features\n\n- **Token-based Authentication**: Secure authentication using DB Session keys\n- **Pandas Integration**: Query results automatically converted to pandas DataFrames\n- **Automatic Table Management**: Create and update tables with schema inference\n- **Batch Operations**: Efficient data pushing with batched inserts\n\n## Installation\n\n```bash\npip install chakra-py\n```\n\n## Quick Start\n\n```python\nfrom chakra_py import Chakra\nimport pandas as pd\n\n# Initialize client\nclient = Chakra(\"YOUR_DB_SESSION_KEY\")\n\n# REQUIRED: Authenticate and set the token\nclient.login()\n\n# Query data (returns pandas DataFrame)\ndf = client.execute(\"SELECT * FROM my_table\")\nprint(df.head())\n\n# Push data to a new or existing table\ndata = pd.DataFrame({\n \"id\": [1, 2, 3],\n \"name\": [\"Alice\", \"Bob\", \"Charlie\"],\n \"score\": [85.5, 92.0, 78.5]\n})\nclient.push(\"students\", data, create_if_missing=True)\n```\n\n## Querying Data\n\nExecute SQL queries and receive results as pandas DataFrames:\n\n```python\n# Simple query\ndf = client.execute(\"SELECT * FROM table_name\")\n\n# Complex query with aggregations\ndf = client.execute(\"\"\"\n SELECT \n category,\n COUNT(*) as count,\n AVG(value) as avg_value\n FROM measurements\n GROUP BY category\n HAVING count > 10\n ORDER BY avg_value DESC\n\"\"\")\n\n# Work with results using pandas\nprint(df.describe())\nprint(df.groupby('category').agg({'value': ['mean', 'std']}))\n```\n\n## Pushing Data\n\nPush data from pandas DataFrames to tables with automatic schema handling:\n\n```python\n# Create a sample DataFrame\ndf = pd.DataFrame({\n 'id': range(1, 1001),\n 'name': [f'User_{i}' for i in range(1, 1001)],\n 'score': np.random.normal(75, 15, 1000).round(2),\n 'active': np.random.choice([True, False], 1000)\n})\n\n# Create new table with inferred schema\nclient.push(\n table_name=\"users\",\n data=df,\n create_if_missing=True # Creates table if it doesn't exist\n)\n\n# Update existing table\nnew_users = pd.DataFrame({\n 'id': range(1001, 1101),\n 'name': [f'User_{i}' for i in range(1001, 1101)],\n 'score': np.random.normal(75, 15, 100).round(2),\n 'active': np.random.choice([True, False], 100)\n})\nclient.push(\"users\", new_users, create_if_missing=False)\n```\n\nThe SDK automatically:\n- Infers appropriate column types from DataFrame dtypes\n- Creates tables with proper schema when needed\n- Handles NULL values and type conversions\n- Performs batch inserts for better performance\n\n## Development\n\nTo contribute to the SDK:\n\n1. Clone the repository\n```bash\ngit clone https://github.com/Chakra-Network/python-sdk.git\ncd chakra-sdk\n```\n\n2. Install development dependencies with Poetry\n```bash\n# Install Poetry if you haven't already\ncurl -sSL https://install.python-poetry.org | python3 -\n\n# Install dependencies\npoetry install\n```\n\n3. Run tests\n```bash\npoetry run pytest\n```\n\n4. Build package\n```bash\npoetry build\n```\n\n## PyPI Publication\n\nThe package is configured for easy PyPI publication:\n\n1. Update version in `pyproject.toml`\n2. Build distribution: `poetry build`\n3. Publish: `poetry publish`\n\n## License\n\nMIT License - see LICENSE file for details.\n\n## Support\n\nFor support and questions, please open an issue in the GitHub repository.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Interact with the Chakra API using Python + Pandas",
"version": "1.0.6",
"project_urls": {
"Homepage": "https://github.com/Chakra-Network/python-sdk",
"Repository": "https://github.com/Chakra-Network/python-sdk"
},
"split_keywords": [
"chakra",
" sdk",
" api",
" data",
" pandas",
" dataframe",
" database"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "077054abb51494fba5a53345f60b5f98fda4e2afcd25b01c2762d81f1322a35b",
"md5": "f646e6ed2ef9cc7744540d71ebe37510",
"sha256": "67d21da2453b2d3a9c1a643260f6ef3244bc3b0c3033d98aeb267992bedcf8da"
},
"downloads": -1,
"filename": "chakra_py-1.0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f646e6ed2ef9cc7744540d71ebe37510",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<3.13,>=3.9",
"size": 7226,
"upload_time": "2025-01-06T03:18:49",
"upload_time_iso_8601": "2025-01-06T03:18:49.516751Z",
"url": "https://files.pythonhosted.org/packages/07/70/54abb51494fba5a53345f60b5f98fda4e2afcd25b01c2762d81f1322a35b/chakra_py-1.0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "66fc381ca1e570d898dd8a8c07bc798c521ec26797a51fa257a2b9dd15d9ed78",
"md5": "b08d96d5a6b0f22ccd8f8481d9aae534",
"sha256": "7f6611e0293205b806b6ad3486600c1a025687ea823a6d072adb37389a30111d"
},
"downloads": -1,
"filename": "chakra_py-1.0.6.tar.gz",
"has_sig": false,
"md5_digest": "b08d96d5a6b0f22ccd8f8481d9aae534",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<3.13,>=3.9",
"size": 6485,
"upload_time": "2025-01-06T03:18:51",
"upload_time_iso_8601": "2025-01-06T03:18:51.691694Z",
"url": "https://files.pythonhosted.org/packages/66/fc/381ca1e570d898dd8a8c07bc798c521ec26797a51fa257a2b9dd15d9ed78/chakra_py-1.0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-06 03:18:51",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Chakra-Network",
"github_project": "python-sdk",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "chakra-py"
}