langid-go includes a feature-rich, high-performance command-line tool. It is fully backwards-compatible with the CLI behaviors of langid.py and langid.c, while offering modern extensions like multiple output formats, URL classification, and a local interactive sandbox.
To compile the langid command-line executable:
go build -o langid ./cmd/langidThis generates a native static binary langid with zero runtime dependencies.
Usage of langid:
-m, --model string
path to .lidg model (optional, uses default if omitted)
-l, --langs string
comma-separated set of target ISO639 language codes (e.g en,de)
--line
line mode: classify each input line (legacy alias: -l)
-b, --batch
batch mode: treat stdin lines or CLI arguments as file paths to classify
-d, --dist
show full distribution over languages (rank mode)
-n, --normalize
normalize confidence scores to probability values (0.0 to 1.0)
-f, --format string
output format for batch mode: classic, csv, or jsonl (default "classic")
--ignore-missing
silently skip missing or unreadable files in batch mode
--max-bytes int
maximum bytes read per stdin, file, request, or URL body (default 4194304)
--serve
start HTTP service mode
--demo
start HTTP service mode and open demo page in web browser
--host string
host to bind HTTP service to (default "127.0.0.1")
--port int
port to bind HTTP service to (default 9008)
-u, --url string
classify the content of a URL
Reads a single document from standard input and prints the best prediction.
$ ./langid -n <<< "This is a simple sentence."
('en', 1.0000)Running ./langid with standard input attached to a terminal automatically boots a Python-style interactive shell.
$ ./langid -n
>>> Hello World
('en', 1.0000)
>>> Bonjour tout le monde
('fr', 1.0000)Processes standard input line-by-line, treating each line as a separate document.
$ printf "hello world\nbonjour tout le monde\n" | ./langid --line
('en', -102.5)
('fr', -105.1)Reads files and classifies them. You can pass file paths directly as command-line arguments, or pipe a list of file paths to standard input.
./langid --batch --format csv file1.txt file2.txtfind . -name "*.md" | ./langid -b -n --format jsonlControl the batch outputs with the --format flag:
classic(default): Matches the original C implementation (langid.c) output format:path,('lang', score)csv: Matches the standard Python implementation (langid.py) batch output format:- Standard: Outputs
path,lang,score(no header row). - Distribution (
-d): Outputs a header followed by scores for all supported columns:path,en,fr,es,de,... file1.txt,-105.1,-240.2,...
- Standard: Outputs
jsonl:- Standard:
{"path":"file1.txt","language":"en","confidence":-105.1} - Distribution (
-d):{"path":"file1.txt","ranking":[{"language":"en","score":-105.1},{"language":"fr","score":-240.2},...]}
- Standard:
By default, batch mode reports "NOSUCHFILE" for unreadable or missing files. Add --ignore-missing to silently skip them.
./langid --batch --ignore-missing file1.txt missing_file.txtFetches a webpage, extracts its plain text, and identifies the language directly from the terminal.
$ ./langid --url "https://example.com" -n
https://example.com 1256 ('en', 1.0000)(Prints: URL, Length in Bytes, and Result)
Run langid as a microservice on your local network:
# Start the HTTP server on port 9008
./langid --serve --port 9008
# Start the server and automatically launch the interactive UI sandbox in your default browser
./langid --demoIdentifies the best language for the given text.
- Request Body: Raw text in POST body, or
application/x-www-form-urlencodedstring with parameterq. - Response Structure (JSON):
{ "responseData": { "language": "en", "confidence": 1.0 }, "responseDetails": null, "responseStatus": 200 }
Ranks all supported languages.
- Request Body: Raw text in POST body, or
application/x-www-form-urlencodedstring with parameterq. - Response Structure (JSON):
{ "responseData": [ ["en", 1.0], ["fr", 0.0], ["es", 0.0] ], "responseDetails": null, "responseStatus": 200 }
Serves the responsive, interactive HTML dashboard sandbox to test classification dynamically in real-time.