fanyi
Translate subtitles and documents from your terminal.
fanyi is a command-line translation tool built for subtitle files. It supports SRT, ASS/SSA, and VTT formats out of the box, with additional support for plain text, Markdown, PDF, DOCX, and audio files. Powered by multiple translation engines including OpenAI, DeepL, and local models via Ollama.
Features
- Subtitle-first design - Native support for SRT, ASS/SSA, and VTT with timing preservation
- Multiple translation engines - OpenAI, DeepL, Ollama (local), or bring your own via plugins
- Batch processing - Translate entire folders of subtitle files in one command
- Context-aware translation - Use
--context-linesto give the engine dialogue context for better translations - Smart caching - Skip already-translated segments to save time and API costs
- Resumable jobs - Pick up where you left off if a translation is interrupted
- Glossary support - Define term mappings to ensure consistent translations
- Format detection - Automatically identifies file formats and encodings (including BOM)
Installation
pip install fanyi
Quick Start (30 seconds)
Translate an SRT subtitle file using the built-in mock engine (no API key needed):
fanyi subs movie.srt --target zh --engine mock
For real translations with OpenAI:
export OPENAI_API_KEY=your-key-here
fanyi subs movie.srt --target ja --engine openai
Translate all subtitles in a folder:
fanyi subs ./subtitles/ --target ko --engine openai
Supported Formats
| Format | Extension | Description |
|---|---|---|
| SRT | .srt |
SubRip subtitle format |
| ASS/SSA | .ass, .ssa |
Advanced SubStation Alpha |
| VTT | .vtt |
WebVTT subtitle format |
| Text | .txt |
Plain text files |
| Markdown | .md |
Markdown documents |
.pdf |
PDF documents (read-only extraction) | |
| DOCX | .docx |
Microsoft Word documents |
| Audio | .mp3, .wav |
Audio transcription + translation |
Supported Engines
| Engine | Description | Requires API Key |
|---|---|---|
| OpenAI | GPT-based translation with high quality | Yes |
| DeepL | Professional translation API | Yes |
| Ollama | Local LLM models (no data leaves your machine) | No |
| Mock | Built-in test engine for development/CI | No |
Configuration
Environment Variables
export OPENAI_API_KEY=your-openai-key
export DEEPL_API_KEY=your-deepl-key
export OLLAMA_HOST=http://localhost:11434
Config File
Create a config file at ~/.config/fanyi/config.yaml:
default_engine: openai
default_target: zh
engines:
openai:
model: gpt-4
temperature: 0.3
deepl:
formality: more
ollama:
model: llama3
host: http://localhost:11434
View current configuration:
fanyi config
Subtitle Translation
The subs command is optimized for subtitle workflows:
# Translate a single file
fanyi subs episode01.srt --target zh
# Translate with dialogue context for better quality
fanyi subs episode01.srt --target zh --context-lines 3
# Batch translate a folder
fanyi subs ./season1/ --target ja --engine openai
Context-Aware Translation
Use --context-lines to send surrounding dialogue lines to the engine. This helps produce translations that account for conversational flow:
fanyi subs interview.vtt --target fr --context-lines 5
CLI Commands
fanyi translate # Translate any supported file
fanyi subs # Subtitle-optimized translation
fanyi list-engines # Show available engines
fanyi list-formats # Show supported formats
fanyi config # View/manage configuration
fanyi check # Verify engine connectivity
fanyi cache # Manage translation cache
fanyi jobs # View and resume translation jobs
fanyi plugins # Manage plugins
fanyi history # View translation history
License
MIT
Metadata
Release files for subfanyi 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| subfanyi-0.1.0.tar.gz | 85.8 kB | Without provenance | Details for subfanyi-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| subfanyi-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for subfanyi-0.1.0-py3-none-any.whl |
Total release size: 148.9 kB
Release files / subfanyi-0.1.0.tar.gz
| Download URL | subfanyi-0.1.0.tar.gz |
|---|---|
| Size | 85.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2c7578c794ed4fb13992c74ed37bb310f5d8de74ef23bfcf79212080f0d0117f
|
|
BLAKE2b-256 checksum How to use checksums |
d8dcf39382548d918c73b94a665dfd06749a1b1fc3192608f37a8204af6188d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.10
|
Release files / subfanyi-0.1.0-py3-none-any.whl
| Download URL | subfanyi-0.1.0-py3-none-any.whl |
|---|---|
| Size | 63.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c2697d0d0241c3d5609ab87e097516c4c0083f5719b4dd7be2b0e797d7c06df1
|
|
BLAKE2b-256 checksum How to use checksums |
ddad5c0472fbedb768cc83b828e4323ef041436cb2a3a23066eb6fc5f5d5b717
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.10
|
Security for subfanyi 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.