Skip to main content

🎙️ 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 😅

Metadata

Release files for gemini-live-ws-server 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gemini-live-ws-server 0.1.2
File Size Uploaded
gemini_live_ws_server-0.1.2.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gemini-live-ws-server 0.1.2
File Interpreter ABI Platform
gemini_live_ws_server-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 14.5 kB

Release files / gemini_live_ws_server-0.1.2.tar.gz

Download URL gemini_live_ws_server-0.1.2.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f9bd10186a2c81910eb3bc1d1abae8da27ce60efa9f794e2ecfb3dd14730cb1c
BLAKE2b-256 checksum
How to use checksums
31f1204e65d0d8d8b659c906dd08c767bb3c05debdf85ca7a8bc1728800bf111
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release files / gemini_live_ws_server-0.1.2-py3-none-any.whl

Download URL gemini_live_ws_server-0.1.2-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
993c8d7f76793c741f4aee12c6b27cfa23b22b28922d8ee7a5e192a9ba18032a
BLAKE2b-256 checksum
How to use checksums
b01d93db184838a3835df38c24822ac06c22cbc5332a5056c79b770441a29c8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page