Skip to main content

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_code calls
  • 🔄 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

  1. Clone the repo
    git clone https://github.com/omanandswami2005/gemini_live_ws_server_pipy.git
    cd gemini_live_ws_server_pipy
    
  2. Create & activate a virtual environment
    python -m venv myenv
    source myenv/bin/activate   # macOS/Linux
    myenv\Scripts\activate    # Windows
    
  3. 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 access
  • JWT_SECRET: 🛡️ Secret for signing/verifying Socket.IO tokens
  • PORT: 🖥️ Server listening port (default: 8080)
  • CORS_ORIGINS: 🌐 Comma-separated origins for CORS
  • DEBUG: 🐞 true or false for 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

  1. Star this repo
  2. 🔀 Fork it
  3. ✨ Create a feature branch (git checkout -b feature/new-thing)
  4. 🛠️ Make changes & commit (git commit -m 'feat: add awesome feature')
  5. 🔄 Push to the branch (git push origin feature/new-thing)
  6. 📥 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gemini_live_ws_server-0.1.2.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gemini_live_ws_server-0.1.2-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

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

Hashes for gemini_live_ws_server-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f9bd10186a2c81910eb3bc1d1abae8da27ce60efa9f794e2ecfb3dd14730cb1c
MD5 c10c13e0f395ff7485d6878a53fda435
BLAKE2b-256 31f1204e65d0d8d8b659c906dd08c767bb3c05debdf85ca7a8bc1728800bf111

See more details on using hashes here.

File details

Details for the file gemini_live_ws_server-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for gemini_live_ws_server-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 993c8d7f76793c741f4aee12c6b27cfa23b22b28922d8ee7a5e192a9ba18032a
MD5 06eba04f9143c9cb6cd8cd1e749934af
BLAKE2b-256 b01d93db184838a3835df38c24822ac06c22cbc5332a5056c79b770441a29c8d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page