# TursoPy

A lightweight, dependency-minimal Python client for Turso databases. Born out of frustration with dependency issues in existing solutions, TursoPy provides a straightforward way to interact with Turso databases without the complexity.
> **Note**: This project isn't meant to compete with libsql-experimental or suggest it's any better or worse. It's simply an alternative born from experiencing dependency issues with existing solutions. While TursoPy might not be as feature-rich as libsql-experimental, it gets the job done with minimal fuss. As a solo developer without corporate backing, I created this to solve my own frustrations and share it with others who might face similar challenges.
## Features
- Simple CRUD operations
- Batch processing support
- Advanced query capabilities including JOINs
- Minimal dependencies (HTTP client via `requests` for sync and `aiohttp` for async)
- Straightforward error handling
- Database creation utilities
## Installation
```
pip install turso-python
Using uv (recommended for local dev):
- Production deps only:
uv pip install -e .
- With dev extras (tests, linting):
uv pip install -e .[dev]
```
If pip install doesn't work, clone the project or download the zip from the realease section
## Quick Start
1. Set up your environment variables (or pass explicitly to the client). Do not commit secrets.
- On Linux/macOS:
```bash
export TURSO_DATABASE_URL="libsql://your_database_url"
export TURSO_AUTH_TOKEN={{TURSO_AUTH_TOKEN}}
```
- On Windows (PowerShell):
```bash
setx TURSO_DATABASE_URL "libsql://your_database_url"
setx TURSO_AUTH_TOKEN "{{TURSO_AUTH_TOKEN}}"
```
Note: The client accepts libsql:// and normalizes it to https:// automatically for HTTP calls.
2. Basic usage:
```python
from turso_python.connection import TursoConnection
from turso_python.crud import TursoCRUD
# Initialize connection (env vars or pass explicit values)
connection = TursoConnection()
crud = TursoCRUD(connection)
# Insert data
data = {"name": "John Doe", "age": 30}
crud.create("users", data)
# Read data
result = crud.read("users", "name = ?", ["John Doe"])
```
## Detailed Usage Guide
### Connection Management
The `TursoConnection` class handles all communication with the Turso API:
```python
from turso_python.connection import TursoConnection
# Using environment variables
connection = TursoConnection()
# Or explicit credentials
connection = TursoConnection(
database_url="your_database_url",
auth_token="your_auth_token"
)
```
### CRUD Operations
#### Create
```python
crud = TursoCRUD(connection)
# Single insert
user_data = {
"name": "Jane Smith",
"email": "jane@example.com",
"age": 25
}
crud.create("users", user_data)
```
#### Read
```python
# Fetch all records
all_users = crud.read("users")
# Fetch with conditions
young_users = crud.read(
table="users",
where="age < ?",
args=["30"]
)
```
#### Update
```python
update_data = {"age": 31}
crud.update(
table="users",
data=update_data,
where="name = ?",
args=["Jane Smith"]
)
```
#### Delete
```python
crud.delete(
table="users",
where="name = ?",
args=["Jane Smith"]
)
```
### Async Usage
```python
import anyio
from turso_python import AsyncTursoConnection, AsyncTursoCRUD
async def main():
async with AsyncTursoConnection() as conn:
crud = AsyncTursoCRUD(conn)
await crud.create("users", {"name": "Alice", "age": 30})
res = await crud.read("users", "age > ?", [20])
print(res)
anyio.run(main)
```
### Batch Operations
For bulk operations, use the `TursoBatch` class:
```python
from turso_python.batch import TursoBatch
batch = TursoBatch(connection)
users = [
{"name": "User 1", "age": 25},
{"name": "User 2", "age": 30},
{"name": "User 3", "age": 35}
]
batch.batch_insert("users", users)
```
### Advanced Queries
The `TursoAdvancedQueries` class handles complex operations:
```python
from turso_python.advanced_queries import TursoAdvancedQueries
advanced = TursoAdvancedQueries(connection)
# Perform a JOIN operation
result = advanced.join_query(
base_table="users",
join_table="orders",
join_condition="users.id = orders.user_id",
select_columns="users.name, orders.order_date",
where="orders.amount > 100"
)
```
### Schema Management
The `TursoSchemaManager` helps with table operations:
```python
from turso_python.crud import TursoSchemaManager
schema_manager = TursoSchemaManager(connection)
# Create a new table
schema = {
"id": "INTEGER PRIMARY KEY",
"name": "TEXT NOT NULL",
"email": "TEXT UNIQUE",
"created_at": "TIMESTAMP DEFAULT CURRENT_TIMESTAMP"
}
schema_manager.create_table("users", schema)
# Drop a table
schema_manager.drop_table("old_table")
```
### Database Creation
```python
from turso_python.crud import TursoClient
client = TursoClient()
# Create a new database
client.create_database(
org_name="your_org",
db_name="new_database",
group_name="default",
api_token="your_api_token"
)
```
## Error Handling
TursoPy includes basic error handling for common scenarios:
```python
try:
result = crud.read("non_existent_table")
except Exception as e:
print(f"An error occurred: {e}")
```
## Best Practices
1. Always use environment variables for sensitive credentials
2. Use batch operations for bulk inserts/updates
3. Close connections when done (handled automatically in most cases)
4. Use proper type hints in query arguments
5. Handle errors appropriately in production code
## Contributing
Contributions are welcome! As a solo developer project, I appreciate any help in improving TursoPy. Please feel free to:
- Report bugs
- Suggest features
- Submit pull requests
- Improve documentation
## License
Apache 2.0 License
## Support
For issues, questions, or suggestions, please open an issue on GitHub. As a solo developer, I'll do my best to respond in a timely manner.
---
Remember: TursoPy is designed to be simple and straightforward. While it might not have all the bells and whistles of other clients, it focuses on reliability and ease of use. Sometimes, simpler is better!
**Note for 2024-11-24, I literally built this yesterday so I'm still tweaking some stuff and fixing some stuff**
Raw data
{
"_id": null,
"home_page": null,
"name": "turso-python",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": "Srikanth <srikanth.gokr@gmail.com>",
"keywords": "aiohttp, async, client, http, libsql, msgspec, sqlite, turso",
"author": null,
"author_email": "Marcus Peterson <marcus.peterson.tech@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/94/27/efe3a4cdde73abe46559d53e771b7da2d8ea23b3701857c1dd92afda67fc/turso_python-1.8.tar.gz",
"platform": null,
"description": "# TursoPy\n\n\n\n\nA lightweight, dependency-minimal Python client for Turso databases. Born out of frustration with dependency issues in existing solutions, TursoPy provides a straightforward way to interact with Turso databases without the complexity.\n\n> **Note**: This project isn't meant to compete with libsql-experimental or suggest it's any better or worse. It's simply an alternative born from experiencing dependency issues with existing solutions. While TursoPy might not be as feature-rich as libsql-experimental, it gets the job done with minimal fuss. As a solo developer without corporate backing, I created this to solve my own frustrations and share it with others who might face similar challenges.\n\n## Features\n\n- Simple CRUD operations\n- Batch processing support\n- Advanced query capabilities including JOINs\n- Minimal dependencies (HTTP client via `requests` for sync and `aiohttp` for async)\n- Straightforward error handling\n- Database creation utilities\n\n## Installation\n```\npip install turso-python\n\nUsing uv (recommended for local dev):\n- Production deps only:\n uv pip install -e .\n- With dev extras (tests, linting):\n uv pip install -e .[dev]\n```\nIf pip install doesn't work, clone the project or download the zip from the realease section\n\n## Quick Start\n\n1. Set up your environment variables (or pass explicitly to the client). Do not commit secrets.\n\n- On Linux/macOS:\n ```bash\n export TURSO_DATABASE_URL=\"libsql://your_database_url\"\n export TURSO_AUTH_TOKEN={{TURSO_AUTH_TOKEN}}\n ```\n \n- On Windows (PowerShell):\n ```bash\n setx TURSO_DATABASE_URL \"libsql://your_database_url\"\n setx TURSO_AUTH_TOKEN \"{{TURSO_AUTH_TOKEN}}\"\n ```\nNote: The client accepts libsql:// and normalizes it to https:// automatically for HTTP calls.\n\n\n2. Basic usage:\n\n```python\nfrom turso_python.connection import TursoConnection\nfrom turso_python.crud import TursoCRUD\n\n# Initialize connection (env vars or pass explicit values)\nconnection = TursoConnection()\ncrud = TursoCRUD(connection)\n\n# Insert data\ndata = {\"name\": \"John Doe\", \"age\": 30}\ncrud.create(\"users\", data)\n\n# Read data\nresult = crud.read(\"users\", \"name = ?\", [\"John Doe\"])\n```\n\n## Detailed Usage Guide\n\n### Connection Management\n\nThe `TursoConnection` class handles all communication with the Turso API:\n\n```python\nfrom turso_python.connection import TursoConnection\n\n# Using environment variables\nconnection = TursoConnection()\n\n# Or explicit credentials\nconnection = TursoConnection(\n database_url=\"your_database_url\",\n auth_token=\"your_auth_token\"\n)\n```\n\n### CRUD Operations\n\n#### Create\n\n```python\ncrud = TursoCRUD(connection)\n\n# Single insert\nuser_data = {\n \"name\": \"Jane Smith\",\n \"email\": \"jane@example.com\",\n \"age\": 25\n}\ncrud.create(\"users\", user_data)\n```\n\n#### Read\n\n```python\n# Fetch all records\nall_users = crud.read(\"users\")\n\n# Fetch with conditions\nyoung_users = crud.read(\n table=\"users\",\n where=\"age < ?\",\n args=[\"30\"]\n)\n```\n\n#### Update\n\n```python\nupdate_data = {\"age\": 31}\ncrud.update(\n table=\"users\",\n data=update_data,\n where=\"name = ?\",\n args=[\"Jane Smith\"]\n)\n```\n\n#### Delete\n\n```python\ncrud.delete(\n table=\"users\",\n where=\"name = ?\",\n args=[\"Jane Smith\"]\n)\n```\n\n### Async Usage\n\n```python\nimport anyio\nfrom turso_python import AsyncTursoConnection, AsyncTursoCRUD\n\nasync def main():\n async with AsyncTursoConnection() as conn:\n crud = AsyncTursoCRUD(conn)\n await crud.create(\"users\", {\"name\": \"Alice\", \"age\": 30})\n res = await crud.read(\"users\", \"age > ?\", [20])\n print(res)\n\nanyio.run(main)\n```\n\n### Batch Operations\n\nFor bulk operations, use the `TursoBatch` class:\n\n```python\nfrom turso_python.batch import TursoBatch\n\nbatch = TursoBatch(connection)\n\nusers = [\n {\"name\": \"User 1\", \"age\": 25},\n {\"name\": \"User 2\", \"age\": 30},\n {\"name\": \"User 3\", \"age\": 35}\n]\n\nbatch.batch_insert(\"users\", users)\n```\n\n### Advanced Queries\n\nThe `TursoAdvancedQueries` class handles complex operations:\n\n```python\nfrom turso_python.advanced_queries import TursoAdvancedQueries\n\nadvanced = TursoAdvancedQueries(connection)\n\n# Perform a JOIN operation\nresult = advanced.join_query(\n base_table=\"users\",\n join_table=\"orders\",\n join_condition=\"users.id = orders.user_id\",\n select_columns=\"users.name, orders.order_date\",\n where=\"orders.amount > 100\"\n)\n```\n\n### Schema Management\n\nThe `TursoSchemaManager` helps with table operations:\n\n```python\nfrom turso_python.crud import TursoSchemaManager\n\nschema_manager = TursoSchemaManager(connection)\n\n# Create a new table\nschema = {\n \"id\": \"INTEGER PRIMARY KEY\",\n \"name\": \"TEXT NOT NULL\",\n \"email\": \"TEXT UNIQUE\",\n \"created_at\": \"TIMESTAMP DEFAULT CURRENT_TIMESTAMP\"\n}\nschema_manager.create_table(\"users\", schema)\n\n# Drop a table\nschema_manager.drop_table(\"old_table\")\n```\n\n### Database Creation\n\n```python\nfrom turso_python.crud import TursoClient\n\nclient = TursoClient()\n\n# Create a new database\nclient.create_database(\n org_name=\"your_org\",\n db_name=\"new_database\",\n group_name=\"default\",\n api_token=\"your_api_token\"\n)\n```\n\n## Error Handling\n\nTursoPy includes basic error handling for common scenarios:\n\n```python\ntry:\n result = crud.read(\"non_existent_table\")\nexcept Exception as e:\n print(f\"An error occurred: {e}\")\n```\n\n## Best Practices\n\n1. Always use environment variables for sensitive credentials\n2. Use batch operations for bulk inserts/updates\n3. Close connections when done (handled automatically in most cases)\n4. Use proper type hints in query arguments\n5. Handle errors appropriately in production code\n\n## Contributing\n\nContributions are welcome! As a solo developer project, I appreciate any help in improving TursoPy. Please feel free to:\n\n- Report bugs\n- Suggest features\n- Submit pull requests\n- Improve documentation\n\n## License\n\nApache 2.0 License\n\n## Support\n\nFor issues, questions, or suggestions, please open an issue on GitHub. As a solo developer, I'll do my best to respond in a timely manner.\n\n---\n\nRemember: TursoPy is designed to be simple and straightforward. While it might not have all the bells and whistles of other clients, it focuses on reliability and ease of use. Sometimes, simpler is better!\n\n**Note for 2024-11-24, I literally built this yesterday so I'm still tweaking some stuff and fixing some stuff**\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "A Python client for Turso/libsql HTTP API with sync and async support",
"version": "1.8",
"project_urls": null,
"split_keywords": [
"aiohttp",
" async",
" client",
" http",
" libsql",
" msgspec",
" sqlite",
" turso"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "44880f2eedbeb6ed9697c295222179a8bb5738f7e73e5b5055783b8f07b1313b",
"md5": "ea4031f50a0c6e54b4b70cd4f73e85d4",
"sha256": "34c8bd402d1e9c5b30a27066686213c90b7ec65ef5a13c4e24d85abf9851762d"
},
"downloads": -1,
"filename": "turso_python-1.8-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ea4031f50a0c6e54b4b70cd4f73e85d4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 24738,
"upload_time": "2025-09-01T08:42:05",
"upload_time_iso_8601": "2025-09-01T08:42:05.281687Z",
"url": "https://files.pythonhosted.org/packages/44/88/0f2eedbeb6ed9697c295222179a8bb5738f7e73e5b5055783b8f07b1313b/turso_python-1.8-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "9427efe3a4cdde73abe46559d53e771b7da2d8ea23b3701857c1dd92afda67fc",
"md5": "0b23dbc0440131c0b4f487e5e3eadce3",
"sha256": "9008547e4e5dfc40d97101e94ff08d2bbb9dd5437c2877876b1dd7a75e6f75f4"
},
"downloads": -1,
"filename": "turso_python-1.8.tar.gz",
"has_sig": false,
"md5_digest": "0b23dbc0440131c0b4f487e5e3eadce3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 42434,
"upload_time": "2025-09-01T08:42:06",
"upload_time_iso_8601": "2025-09-01T08:42:06.917741Z",
"url": "https://files.pythonhosted.org/packages/94/27/efe3a4cdde73abe46559d53e771b7da2d8ea23b3701857c1dd92afda67fc/turso_python-1.8.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-01 08:42:06",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "turso-python"
}