A Python ASGI Socket.IO server proxying to Gemini Live via WebSockets
Project description
🎙️ Gemini Live Web Socket Server
A Python ASGI Socket.IO server that proxies to Google’s Gemini API over WebSockets
Bridging real-time clients with powerful AI services, complete with JWT authentication, CORS support, and metrics!
🚀 Features
- 🔄 Real-time bi-directional messaging via Socket.IO
- 🌐 ASGI server built on FastAPI + Uvicorn
- 🛡️ JWT Authentication (or pluggable auth middleware)
- 🔧 Tool Presets for
translate_text,summarize_text,generate_codecalls - 🔄 WebSocket Bridge to Gemini (
models/gemini-2.0-flash-exp) - 📊 Optional Metrics (active connections, processed messages, errors)
- 🛬 Graceful Startup & Shutdown
- 🔧 Configurable : CORS, retry/backoff, hooks, debug logging
📦 Installation
- Clone the repo
git clone https://github.com/omanandswami2005/gemini_live_ws_server_pipy.git cd gemini_live_ws_server_pipy
- Create & activate a virtual environment
python -m venv myenv source myenv/bin/activate # macOS/Linux myenv\Scripts\activate # Windows
- Install dependencies
pip install . # published on PyPI
Tip: you can also install directly from PyPI:
pip install --index-url https://pypi.org/simple/gemini_live_ws_server
⚙️ Configuration
Create a .env file or pass flags to your script:
GOOGLE_API_KEY=your_google_api_key_here
JWT_SECRET=super_secret_key
PORT=8080
CORS_ORIGINS=http://localhost:3000,http://yourdomain.com
DEBUG=true
🔑 Environment Variables :
GOOGLE_API_KEY: 🔗 Your Google Cloud API key with Generative API accessJWT_SECRET: 🛡️ Secret for signing/verifying Socket.IO tokensPORT: 🖥️ Server listening port (default: 8080)CORS_ORIGINS: 🌐 Comma-separated origins for CORSDEBUG: 🐞trueorfalsefor verbose logging
🎬 Usage
python -m gemini_live_ws_server.main_server
OR using Uvicorn directly:
uvicorn gemini_live_ws_server.main_server:server --host 127.0.0.1 --port 8080 --reload
Once running, clients can connect to ws://your_host:PORT/socket.io/ with a valid JWT:
import io from 'socket.io-client';
const socket = io('http://localhost:8080', {
auth: { token: '<YOUR_JWT_TOKEN>' }
});
socket.on('ready', () => console.log('🟢 Connected!'));
socket.on('message', msg => console.log('📨 AI:', msg));
💡 Examples
Translate Text
socket.emit('message', {
toolCall: {
functionName: 'translate_text',
arguments: { text: 'Hello, world!', targetLanguage: 'es' }
}
});
Summarize Text
socket.emit('message', {
toolCall: {
functionName: 'summarize_text',
arguments: { text: longParagraph, maxLength: 50 }
}
});
📝 Contributing
- ⭐ Star this repo
- 🔀 Fork it
- ✨ Create a feature branch (
git checkout -b feature/new-thing) - 🛠️ Make changes & commit (
git commit -m 'feat: add awesome feature') - 🔄 Push to the branch (
git push origin feature/new-thing) - 📥 Open a Pull Request
We welcome bug reports, feature requests, and code contributions! ❤️
📜 License
This project is licensed under the Apache 2.0
Made with ❤️ by omiii 😅
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
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 gemini_live_ws_server-0.1.2.tar.gz.
File metadata
- Download URL: gemini_live_ws_server-0.1.2.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9bd10186a2c81910eb3bc1d1abae8da27ce60efa9f794e2ecfb3dd14730cb1c
|
|
| MD5 |
c10c13e0f395ff7485d6878a53fda435
|
|
| BLAKE2b-256 |
31f1204e65d0d8d8b659c906dd08c767bb3c05debdf85ca7a8bc1728800bf111
|
File details
Details for the file gemini_live_ws_server-0.1.2-py3-none-any.whl.
File metadata
- Download URL: gemini_live_ws_server-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
993c8d7f76793c741f4aee12c6b27cfa23b22b28922d8ee7a5e192a9ba18032a
|
|
| MD5 |
06eba04f9143c9cb6cd8cd1e749934af
|
|
| BLAKE2b-256 |
b01d93db184838a3835df38c24822ac06c22cbc5332a5056c79b770441a29c8d
|