Official Python client for GitDB - GitHub-backed NoSQL database
Project description
GitDB Python SDK
Official Python client for GitDB - GitHub-backed NoSQL database.
Features
- 🚀 Easy to use - Familiar MongoDB-like API
- 🔗 Connection management - Automatic reconnection and health checks
- 📊 GraphQL support - Full GraphQL client with introspection
- 🔒 Type safety - Full type hints and Pydantic models
- ⚡ Async support - Modern async/await API
- 🛡️ Error handling - Comprehensive error types and handling
- 🔧 Flexible configuration - Environment variables and custom config
Installation
pip install gitdb-client
Quick Start
Basic Usage
import asyncio
from gitdb import GitDB
async def main():
# Initialize client
db = GitDB.from_environment()
# Connect and use
await db.connect()
users = db.collection('users')
# Insert a document
user = await users.insert({
'name': 'John Doe',
'email': 'john@example.com',
'age': 30
})
# Find documents
all_users = await users.find()
john = await users.find_one({'name': 'John Doe'})
# Update document
await users.update(user['document']['_id'], {'age': 31})
# Delete document
await users.delete(user['document']['_id'])
await db.disconnect()
# Run the example
asyncio.run(main())
Environment Variables
import os
# Set environment variables
os.environ['GITDB_TOKEN'] = 'ghp_your_github_token_here'
os.environ['GITDB_OWNER'] = 'your-username'
os.environ['GITDB_REPO'] = 'your-database-repo'
os.environ['GITDB_HOST'] = 'localhost'
os.environ['GITDB_PORT'] = '7896'
# Use from environment
db = GitDB.from_environment()
API Reference
GitDB Client
Constructor
GitDB(config: GitDBConfig)
Config Options:
token(required): GitHub personal access tokenowner(required): GitHub username or organizationrepo(required): GitHub repository namehost(optional): GitDB server host (default: 'localhost')port(optional): GitDB server port (default: 7896)timeout(optional): Request timeout in ms (default: 30000)retries(optional): Number of retry attempts (default: 3)
Methods
# Connection management
await db.connect(): None
await db.disconnect(): None
db.is_connected(): bool
await db.get_status(): ConnectionStatus
await db.ping(): bool
await db.health(): Any
# Collection management
db.collection(name: str): Collection
await db.list_collections(): List[str]
await db.create_collection(name: str): None
await db.delete_collection(name: str): None
# Utility methods
await db.use_collection(name: str): Collection
# Static methods
GitDB.from_environment(): GitDB
GitDB.from_config(config: GitDBConfig): GitDB
Collection API
Methods
# Create operations
await collection.insert(document: Dict[str, Any]): Dict[str, Any]
# Read operations
await collection.find(query: Optional[Dict[str, Any]] = None): Dict[str, Any]
await collection.find_one(query: Optional[Dict[str, Any]] = None): Optional[Dict[str, Any]]
await collection.find_by_id(id: str): Optional[Dict[str, Any]]
await collection.count(query: Optional[Dict[str, Any]] = None): int
# Update operations
await collection.update(id: str, update: Dict[str, Any]): Dict[str, Any]
# Delete operations
await collection.delete(id: str): Dict[str, Any]
Examples
See the examples/ directory for complete working examples:
basic_test.py- Basic connection and operationscrud_test.py- CRUD operationsgraphql_test.py- GraphQL queries and mutations
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
MIT License - see LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
gitdb_client-1.0.0.tar.gz
(9.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gitdb_client-1.0.0.tar.gz.
File metadata
- Download URL: gitdb_client-1.0.0.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7c178d44dd854dbe9e7217396bdaad389d9c9c5685ea4a12830a5c6875b9f77
|
|
| MD5 |
dd1c5daa300622ed31f9e7679427f850
|
|
| BLAKE2b-256 |
8d6a21d133af783cf634ba7cd3ca6d99b5b2d1faa8425fa9ab0580f2c26a3754
|
File details
Details for the file gitdb_client-1.0.0-py3-none-any.whl.
File metadata
- Download URL: gitdb_client-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91b0936b5021817b35e1157e28ddddfe7af41dbf82522793e34d4ae995b117fd
|
|
| MD5 |
7c2fb67f16848097d042361c9c7d2891
|
|
| BLAKE2b-256 |
f9b88e3e85579991be452f37a961eb768d31a23a8e1cf2a00a3819af222c8b21
|