Skip to main content

Local GPU translation Python library + MCP server — TranslateGemma via Ollama, 57 languages, zero cloud dependency

Project description

日本語 | 中文 | Español | Français | हिन्दी | Italiano | Português (BR)

py-polyglot

Local GPU translation Python library + MCP server — TranslateGemma via Ollama, 57 languages, zero cloud dependency.

CI Codecov PyPI Python License Landing Page Handbook


Python port of polyglot-mcp. Use as a pip-installable library for your Python projects or as an MCP server for Claude Code, Claude Desktop, and other MCP clients.

Features

  • 57 languages — TranslateGemma via Ollama, running 100% locally on your GPU
  • Zero cloud dependency — no API keys, no internet required after model download
  • Dual-use — Python library API + MCP server in one package
  • Markdown-aware — preserves code blocks, tables, HTML, URLs, badges
  • Smart caching — segment-level cache with fuzzy matching (translation memory)
  • Software glossary — 12 built-in tech terms for accurate translations
  • Auto-everything — auto-starts Ollama, auto-pulls models on first use
  • GPU-safe — semaphore-controlled concurrency prevents VRAM overload
  • Production-hardened — connection pooling, structured logging, 100 tests

Requirements

  • Python >= 3.10
  • Ollama installed locally
  • GPU with sufficient VRAM for your chosen model:
    • translategemma:4b — 3.3 GB (fast, good quality)
    • translategemma:12b — 8.1 GB (balanced, recommended)
    • translategemma:27b — 17 GB (slow, best quality)

Install

pip install polyglot-gpu

Library Usage

import asyncio
from pypolyglot import translate, translate_markdown, translate_all

async def main():
    # Simple translation
    result = await translate("Hello world", "en", "ja")
    print(result.translation)  # こんにちは世界

    # Markdown translation (preserves structure)
    md = "## Features\n\nLocal GPU translation with **zero cloud dependency**."
    result = await translate_markdown(md, "en", "fr")
    print(result.markdown)

    # Multi-language (7 languages at once)
    result = await translate_all(md, source_lang="en")
    for r in result.results:
        print(f"{r.name}: {r.status}")

asyncio.run(main())

Options

from pypolyglot import translate, TranslateOptions, GlossaryEntry

# Custom model
result = await translate("Hello", "en", "ja",
    TranslateOptions(model="translategemma:4b"))

# Custom glossary
result = await translate("Deploy the Widget", "en", "ja",
    TranslateOptions(glossary=[
        GlossaryEntry("Widget", {"ja": "ウィジェット"})
    ]))

# Streaming
result = await translate("Hello world", "en", "ja",
    TranslateOptions(on_token=lambda t: print(t, end="")))

MCP Server Usage

Claude Code

{
  "mcpServers": {
    "polyglot-gpu": {
      "command": "polyglot-gpu"
    }
  }
}

Or run directly:

python -m pypolyglot

MCP Tools

Tool Description
translate_text Translate text between any of 57 languages
translate_md Translate markdown while preserving structure
translate_all_langs Translate into multiple languages at once
list_languages List all 57 supported languages
check_status Check Ollama + model availability

Architecture

MCP Client (Claude Code, etc.)
      │ MCP protocol (stdio)
      ▼
┌──────────────────┐
│   server.py      │  5 MCP tools (FastMCP)
├──────────────────┤
│  translate.py    │  Chunking, batching, streaming
│  markdown.py     │  Markdown segmentation
│  translate_all   │  Multi-language orchestrator
│  semaphore.py    │  GPU-safe concurrency
│  validate.py     │  Output validation
├──────────────────┤
│   ollama.py      │  httpx pooled client → Ollama
│   cache.py       │  Segment cache + fuzzy memory
│  glossary.py     │  Software term dictionary
│ languages.py     │  57 language definitions
│   polish.py      │  Post-translation cleanup
│   errors.py      │  Structured error class
└──────────────────┘
      │ HTTP (httpx)
      ▼
   Ollama + TranslateGemma (GPU)

Environment Variables

Variable Default Description
POLYGLOT_MODEL translategemma:12b Default Ollama model
POLYGLOT_CONCURRENCY 1 Max concurrent Ollama calls

Security

  • All translation runs locally — zero data leaves your machine
  • No telemetry, no API keys, no cloud dependency
  • See SECURITY.md for threat model

License

MIT


Built by MCP Tool Shop

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

polyglot_gpu-1.0.5.tar.gz (114.8 kB view details)

Uploaded Source

Built Distribution

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

polyglot_gpu-1.0.5-py3-none-any.whl (30.9 kB view details)

Uploaded Python 3

File details

Details for the file polyglot_gpu-1.0.5.tar.gz.

File metadata

  • Download URL: polyglot_gpu-1.0.5.tar.gz
  • Upload date:
  • Size: 114.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for polyglot_gpu-1.0.5.tar.gz
Algorithm Hash digest
SHA256 1f3849a59ac85531a8d2998dc163c03dade009e306b9cdbad657f96fc4ea8b94
MD5 da96e19af9394adc370918625e57f70c
BLAKE2b-256 8ae418ddcd2ffba3f5c891d6b4108f18364629cc88ea0edb14335c70776cb999

See more details on using hashes here.

Provenance

The following attestation bundles were made for polyglot_gpu-1.0.5.tar.gz:

Publisher: publish.yml on mcp-tool-shop-org/py-polyglot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file polyglot_gpu-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: polyglot_gpu-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 30.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for polyglot_gpu-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 3bf36c6c538d62feb942083ab4e96c8d866fb1483f3ac1b8806df4583514cd01
MD5 111c36a5488cf0eaff532696d075c6ca
BLAKE2b-256 51d9aa2c2464cb3a8663bf420a7504612413d83771bac7ebd95a49868a16ebe5

See more details on using hashes here.

Provenance

The following attestation bundles were made for polyglot_gpu-1.0.5-py3-none-any.whl:

Publisher: publish.yml on mcp-tool-shop-org/py-polyglot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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