Charset Normalizer

A pure-Python universal charset detector that turns text of unknown encoding into clean Unicode.

Library
PyPI
v3.5.2
805 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
83 /100 Excellent
Development Activity 96
Maintenance 96
Community 52
Maturity 60
Momentum 28

Technical Analysis

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

Charset Normalizer is a pure-Python library that detects the character encoding of arbitrary byte streams and normalizes their contents to Unicode. Motivated by the limitations of Chardet, it takes a fundamentally different, heuristic approach: instead of relying on trained statistical weights per encoding, it brute-forces decoding across every IANA-supported codec and scores each candidate by how much “mess” and how much linguistic coherence the decoded text exhibits.

Shipped under the permissive MIT license with zero runtime dependencies, it supports 99 encodings, can register custom codecs, detects the spoken language of the text, and guards against UnicodeDecodeError. It is one of the most widely installed packages in the Python ecosystem, serving as the default encoding detector behind the Requests HTTP client.

What You Get

  • A high-level Python API (from_path, from_bytes, from_fp) that returns ranked charset matches with a convenient .best() accessor
  • A normalizer command-line tool that prints JSON detection results and can rewrite files to Unicode
  • A chardet-compatible detect() function for zero-effort migration from Chardet
  • Support for 99 IANA encodings, custom codec registration, BOM/signature handling, and spoken-language detection

Common Use Cases

  • Decoding user-uploaded files, subtitles, or scraped web content whose encoding is unknown
  • Powering the automatic response-encoding detection inside HTTP clients such as Requests
  • Batch-normalizing legacy documents from mixed or unknown code pages into UTF-8

Under The Hood

Architecture

Detection is driven by from_bytes in src/charset_normalizer/api.py, which iterates over a precomputed multibyte-first ordering of IANA codecs (IANA_SUPPORTED_MB_FIRST) so genuine CJK content short-circuits quickly. For each candidate encoding it decodes the payload in chunks via cut_sequence_chunks (utils.py), scores decoding “mess” with mess_ratio from md.py (a pipeline of MessDetector plugins), and measures linguistic coherence and language with coherence_ratio from cd.py. Signatures and BOMs are stripped through identify_sig_or_bom, and results are ranked and returned as CharsetMatches/CharsetMatch objects (models.py) exposing the chosen encoding, aliases, alternatives, chaos, and coherence.

Tech Stack

Written in pure Python targeting 3.7+ with full type hints (py.typed) and from __future__ import annotations throughout. It has zero runtime dependencies. The build uses setuptools with an optional mypyc compilation hook (backend-path = ["_mypyc_hook"]) that compiles hot paths to C extensions for speed while keeping a pure-Python fallback. Large encoding tables live in constant.py.

Code Quality

The repository is well tested, with 14 test modules covering base detection, coherence, legacy detect() behavior, edge cases, full detection, binary detection, large payloads, logging, and the CLI. It ships pre-commit hooks, a coverage configuration, an OSV scanner config, and a documented security policy, and carries the OpenSSF best-practices badge. Code is consistently typed and modular.

API Design The public surface is deliberately small and ergonomic: from_path('file'), then str(results.best()) gets you readable text in two lines, while from_bytes/from_fp cover in-memory and stream inputs. A chardet-compatible detect() eases migration, the normalizer CLI emits clean JSON, and extensive Read the Docs documentation covers advanced tuning such as chaos thresholds and codec isolation.

Used by 23 apps in this directory

Python
62%
Apache 2.0

marimo

Data Engineering · Developer Tools

23,309

A reactive Python notebook that eliminates hidden state, runs reproducibly, and deploys as a web app or script — stored as pure Python, built for the AI era.

View details
90
Repo Health
91
Technical
65
Dependency
Built with
Python 62%
TypeScript 37%
Updated today
Python
67%
AGPL 3.0

MiroFish

AI Agents · AI Development

81,570

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
65
Repo Health
65
Technical
79
Dependency
Built with
Python 67%
Vue 33%
Updated 1 weeks ago
Python
73%
AGPL 3.0

OpenViking

AI Development · AI Memory · Databases

40,705

An open-source context database that gives AI agents a unified filesystem for memory, resources, and skills with hierarchical tiered retrieval.

View details
85
Repo Health
75
Technical
64
Dependency
Built with
Python 73%
TypeScript 12%
Rust 11%
Updated today
Go
71%
Apache 2.0

OSV.dev

Security

3,001

Google's open-source vulnerability database that maps CVEs to exact package versions across 50+ ecosystems with a public API and data dumps.

View details
87
Repo Health
82
Technical
66
Dependency
Built with
Go 71%
Python 19%
Updated yesterday
TypeScript
50%
Other

Phase Console

Devops · Security

931

End-to-end encrypted secrets management for engineering teams — from local dev to Kubernetes production.

View details
85
Repo Health
73
Technical
63
Dependency
Built with
TypeScript 50%
Python 48%
Updated yesterday
Rust
63%
MIT

PostgresML

AI Development · Databases

6,823

Run ML training and LLM inference natively inside PostgreSQL with GPU acceleration — no data movement required.

View details
51
Repo Health
76
Technical
64
Dependency
Built with
Rust 63%
JavaScript 11%
Updated 1 years ago
TypeScript
98%
MIT

Promptfoo

AI Development

26,358

An open-source CLI and library for evaluating and red-teaming LLM applications — replace trial-and-error prompt engineering with systematic evals, vulnerability scanning, and CI/CD integration.

View details
90
Repo Health
73
Technical
67
Dependency
Built with
TypeScript 98%
Updated today
TypeScript
98%
Apache 2.0

rowboat

AI Assistants · AI Development

18,060

Build, test, and deploy multi-agent AI workflows with a visual editor, RAG data sources, MCP tool integration, and a production-ready REST API.

View details
88
Repo Health
72
Technical
65
Dependency
Built with
TypeScript 98%
Updated yesterday
Python
76%
Apache 2.0

Second Me

AI Assistants · Productivity

15,687

Train a locally hosted AI twin on your own memories—then connect it to the world through a decentralized identity network.

View details
41
Repo Health
75
Technical
68
Dependency
Built with
Python 76%
TypeScript 19%
Updated 1 years 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