gsdk 🚀
gsdk (Gemini SDK) is a lightweight, high-performance Python wrapper for the Google Gemini API (built on the modern google-genai). It is designed for production use, offering automatic key rotation, session persistence, and real-time streaming.
✨ Key Features
- 🔑 Smart Key Rotation: Automatically switch between multiple API keys when you hit rate limits (429/403).
- 🌊 Streaming Support: Real-time response generation with automatic history updates.
- 🔄 Configurable Retries: Set custom retry counts and delays for maximum stability.
- 💾 Session Persistence: Built-in support for File and Redis storage.
- ⚙️ Full Flexibility: Pass any generation parameter (
temperature,top_p,max_tokens) globally or per request. - 🔍 Google Search Grounding: Integrated real-time web search capabilities.
- 📁 Media Support: Simplified async file uploads for multimodal tasks.
📦 Installation
pip install gsdk
🚀 Quick Start
Basic Chat
import asyncio
from gsdk import GeminiSDK
async def main():
sdk = GeminiSDK(api_keys=["YOUR_API_KEY"], model_name="gemini-flash-latest")
response = await sdk.ask("session_1", "Hello! Who are you?")
print(f"AI: {response.text}")
asyncio.run(main())
🌊 Real-time Streaming
Perfect for chat interfaces where you want to show text as it is generated.
async def stream_example():
sdk = GeminiSDK(api_keys=["KEY_1", "KEY_2"])
print("AI: ", end="", flush=True)
async for chunk in sdk.ask_stream("session_1", "Write a long poem about coding."):
print(chunk, end="", flush=True)
asyncio.run(stream_example())
🛠 Advanced Usage
1. Production Storage (Redis)
Share session history across multiple workers or servers.
from gsdk.storage import RedisStorage
storage = RedisStorage(host='localhost', port=6379)
sdk = GeminiSDK(api_keys=["..."], storage=storage)
2. Handling Images and Files
# Upload image or document
media = await sdk.media.upload_file("chart.png")
# Multimodal request
response = await sdk.ask("session_2", [media, "Analyze this chart."])
print(response.text)
3. Google Search Grounding
sdk = GeminiSDK(api_keys=["..."], use_search=True)
response = await sdk.ask("news", "What's happening in AI today?")
print(f"Sources used: {response.sources}")
📖 API Reference
GeminiSDK Methods
| Method | Description |
|---|---|
ask(session_id, content, **kwargs) |
Sends a message and returns a full GeminiResponse. |
ask_stream(session_id, content, **kwargs) |
Async Generator. Yields text chunks and saves history after completion. |
media.upload_file(path) |
Uploads a file to Google servers for multimodal input. |
Configuration Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
api_keys |
List[str] |
Required | List of keys for rotation. |
model_name |
str |
gemini-3-flash-preview |
The Gemini model version. |
storage |
BaseStorage |
FileStorage |
How to store conversation history. |
max_retries |
int |
keys * 3 |
Total attempts for failed requests. |
retry_delay |
float |
5.0 |
Seconds to wait after a rate limit. |
**gen_config |
kwargs |
None |
Global defaults for temperature, top_p, etc. |
🤝 Contributing
- Fork the Project.
- Create your Feature Branch.
- Commit your Changes.
- Push to the Branch.
- Open a Pull Request.
📜 License
Distributed under the MIT License.
gsdk — Powering the next generation of Gemini applications. 🚀
Metadata
Release files for gsdk 1.1.0
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 | |
|---|---|---|---|---|
| gsdk-1.1.0.tar.gz | 7.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gsdk-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.4 kB
Release files / gsdk-1.1.0.tar.gz
| Download URL | gsdk-1.1.0.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3b5b1773276d22b1733c00faeff02d16057b32f5fdceabde83403fa3db247627
|
|
BLAKE2b-256 checksum How to use checksums |
14f1e276a7d6dd74497e93e665efea9221e87934e7f23450b371e2bcf41f1384
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / gsdk-1.1.0-py3-none-any.whl
| Download URL | gsdk-1.1.0-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2a51100c9643cd1b39c6fa5cc630e625f6264c75b9b9915a8f60754050d43ade
|
|
BLAKE2b-256 checksum How to use checksums |
9fe30c07df3ee00c8f2a01aa021129f2a4ebcee8828a099f4aa58a62388f0d49
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Security for gsdk 1.1.0
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.