chardet

Universal character encoding detector for Python with built-in language and MIME type detection.

Library
PyPI
v7.6.0
2,670 stars
0BSD

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
82 /100 Excellent
Development Activity 84
Maintenance 72
Community 72
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
87 /100 Excellent
Architecture 85
Code Quality 88
Innovation 91
Learning Curve 90

chardet is a universal character encoding detector for Python that identifies the encoding of raw byte strings without requiring you to know it in advance. Originally created in 2006 as a port of Mozilla’s universal charset detection library, chardet 7 is a ground-up rewrite that trades the original’s LGPL license for the more permissive 0BSD and delivers dramatically better accuracy and speed while preserving the same public API.

The library runs byte data through a multi-stage detection pipeline — BOM sniffing, magic-number identification, structural probing, byte-validity filtering, and bigram statistical models — to identify the most likely encoding, plus the detected language and a MIME type guess for binary formats. It works both as a one-shot detect() call and as a streaming UniversalDetector for large files, and ships a chardetect CLI for ad hoc use from the shell.

What You Get

  • A detect() function that returns encoding, confidence, and language for a byte string in one call
  • A detect_all() function that ranks every plausible encoding candidate by confidence
  • A UniversalDetector class for incremental/streaming detection of large files without loading them fully into memory
  • A chardetect command-line tool for detecting encodings of files directly from the shell
  • Encoding-era and include/exclude filters to narrow the candidate set to encodings relevant to your use case

Common Use Cases

  • Reading text files of unknown encoding uploaded by users or pulled from third-party sources
  • Normalizing scraped HTML/XML content to UTF-8 before parsing
  • Processing legacy data exports (CSV, logs, email) written in regional encodings like Windows-1251 or EUC-JP
  • Building command-line or batch tooling that needs to sniff encodings of arbitrary files

Under The Hood

Architecture - A detect()/detect_all() call flows into run_pipeline() (pipeline/orchestrator.py), which runs a sequence of discrete stages against the byte data: BOM detection (pipeline/bom.py), a binary-content check (pipeline/binary.py), ASCII detection, magic-number identification (pipeline/magic.py), markup-charset sniffing (pipeline/markup.py), escape-sequence detection for encodings like ISO-2022 (pipeline/escape.py), UTF-8/UTF-16/UTF-32 pattern detection (pipeline/utf8.py, pipeline/utf1632.py), structural scoring for CJK lead-byte diversity and multibyte coverage (pipeline/structural.py), validity filtering (pipeline/validity.py), and finally bigram statistical scoring (pipeline/statistical.py) against per-language BigramProfile models. Language tagging (pipeline/language.py) and postprocessing (pipeline/postprocess.py) run last, producing DetectionResult objects that get converted to dicts and optionally remapped through output_names.py for legacy-compatible naming. The candidate encoding set itself comes from a central EncodingInfo registry (registry.py) that tags each of the 99 supported encodings with metadata used for era/include/exclude filtering. UniversalDetector (detector.py, universaldetector.py) wraps the same pipeline behind an incremental .feed()/.close() interface for streaming use.

Tech Stack - Pure Python, zero runtime dependencies, requires Python 3.10+ and works on PyPy. Packaged with Hatchling plus hatch-vcs for git-tag-derived versioning. An optional hatch-mypyc build hook can compile the hot-path pipeline modules (structural, validity, statistical, utf1632, utf8, escape, language, orchestrator, confusion, magic, ascii, postprocess) to C extensions, which the project credits for a large share of its claimed speedup over prior releases. Dev tooling is Ruff (lint + format, 88-char lines, py310 target) and mypy for type checking, with docs built via Sphinx and hosted on Read the Docs.

Code Quality - 39 test_*.py files under tests/ (plus a scripts/tests suite), run under a strict pytest configuration (--strict-markers, --strict-config) with pytest-cov for coverage and pytest-xdist for parallel execution, plus custom benchmark/serial markers. The codebase uses dataclasses (EncodingInfo, DetectionResult), Literal types for the full encoding registry, and mypy-checked type hints throughout; module docstrings explicitly call out mypyc compilation constraints (e.g. why from __future__ import annotations is intentionally omitted in compiled modules). Input validation (_validate_max_bytes, _validate_encoding) raises on bad arguments rather than silently coercing them.

API Design - The public surface is deliberately small — detect(), detect_all(), UniversalDetector, EncodingEra, LanguageFilter — with every parameter thoroughly docstringed and sensible defaults, so chardet.detect(byte_str) works with zero configuration. Backward compatibility is explicit and intentional: despite being a ground-up rewrite, chardet 7 preserves the exact chardet 5.x/6.x API and default output shape (compat_names, a deprecated should_rename_legacy alias), and the chardetect CLI mirrors the library API almost 1:1 (--minimal, --language, -e/--encoding-era). Documentation is dense: a README quick-start with runnable snippets, a full Sphinx docs site with API reference, ADRs, a how-it-works page, and a FAQ.

Used by 11 apps in this directory

Python
79%
Apache 2.0

changedetection.io

Monitoring

34,605

Self-hosted website change detection with AI-powered smart alerts, browser automation, price tracking, and 85+ notification channels.

View details
91
Repo Health
80
Technical
68
Dependency
Built with
Python 79%
Updated 1 weeks ago
Python
70%
Apache 2.0

GPT Researcher

AI Assistants · Productivity

29,650

The pioneering open-source autonomous AI agent that conducts deep, multi-source research and produces citation-backed reports exceeding 2,000 words — faster and more reliably than any human researcher.

View details
91
Repo Health
91
Technical
63
Dependency
Built with
Python 70%
TypeScript 18%
Updated 6 days ago
TypeScript
83%
Apache 2.0

Grist

Databases · No Code Platforms

11,875

A modern relational spreadsheet that combines Python-powered formulas, drag-and-drop dashboards, and granular access controls in a self-hostable, SQLite-backed data platform.

View details
91
Repo Health
93
Technical
66
Dependency
Built with
TypeScript 83%
Python 11%
Updated 5 days ago
HTML
46%
LGPL-2.1

Horilla

ERP · Human Resources

1,437

Open-source HRMS covering recruitment, attendance, payroll, and biometrics in one self-hosted Django application.

View details
91
Repo Health
60
Technical
65
Dependency
Built with
HTML 46%
Python 38%
JavaScript 12%
Updated 4 days ago
Python
69%
MIT

Langflow

AI Agents · AI Development

155,319

Build, test, and deploy AI agents and RAG workflows visually with native API and MCP server export.

View details
90
Repo Health
85
Technical
65
Dependency
Built with
Python 69%
TypeScript 22%
Updated 4 days ago
C++
66%
Other

Memgraph

AI Development · Databases

4,581

High-performance in-memory graph database for AI context and real-time analytics

View details
90
Repo Health
79
Technical
69
Dependency
Built with
C++ 66%
Python 18%
Updated 5 days ago
Python
67%
AGPL 3.0

MiroFish

AI Agents · AI Development

75,037

A universal swarm intelligence engine that spawns thousands of autonomous AI agents to simulate and predict how real-world events unfold across social, financial, and political domains.

View details
79
Repo Health
65
Technical
79
Dependency
Built with
Python 67%
Vue 33%
Updated 2 weeks ago
Python
52%
Other

Odoo

CRM · ERP · Productivity

54,709

The open source ERP platform that integrates CRM, accounting, inventory, manufacturing, and 60+ business apps into one seamlessly connected suite.

View details
87
Repo Health
82
Technical
64
Dependency
Built with
Python 52%
JavaScript 44%
Updated 5 days ago
Python
37%
Other

Open WebUI

AI Agents · AI Assistants

153,390

The extensible, privacy-first AI platform that runs Ollama, OpenAI, and any LLM backend behind a polished, feature-packed web interface.

View details
91
Repo Health
75
Technical
66
Dependency
Built with
Python 37%
Svelte 34%
JavaScript 21%
Updated 4 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers