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


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

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 client → localhost:11434
│   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.3.tar.gz (92.7 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.3-py3-none-any.whl (30.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: polyglot_gpu-1.0.3.tar.gz
  • Upload date:
  • Size: 92.7 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.3.tar.gz
Algorithm Hash digest
SHA256 631d675fac13f460dc61ab5cff73c612bff8acdcfb3e3c5c947cdc4ef865d671
MD5 d780d73da9f8ab435fbd8af7062351f1
BLAKE2b-256 68c54a872119c694815249a9c4e08426541060c181ab0f6616f0b30d5b854745

See more details on using hashes here.

Provenance

The following attestation bundles were made for polyglot_gpu-1.0.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: polyglot_gpu-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 30.8 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 799063b8e61e1a9d84ec6caa83a31d3f0ba6b070e566756fec31e8110e8e5f9d
MD5 88a700ebd72e8e835428594332c9294d
BLAKE2b-256 28b9e7fa60db656278aabae18ea8c45cff80a60ecb20c73c767a526c9771a00d

See more details on using hashes here.

Provenance

The following attestation bundles were made for polyglot_gpu-1.0.3-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