# charset-normalizer — card for AI agents

Detect and normalize character encoding in text with modern alternative to Chardet.

Category: Utilities · PyPI package `charset-normalizer` · latest version 3.5.2 (checked 2026-11-01)
Install: `pip install charset-normalizer`
License: MIT (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Numbers (AgentGid data)
- Gid Score: 67.6 (#509 of all tools, 59 of 408 in its category)
- Used in 67 public projects set up for AI coding agents (1.1%)
- Downloads last week: 356,716,032 (as of 2026-11-24), +12.2% over 4 weeks
- GitHub stars: 810 (as of 2026-11-24)
- Last push: 2026-11-23

## Often used with
Requests 94.0%, urllib3 91.0%, Click 76.1%, Pydantic 76.1%

## Links
- AgentGid page: https://agentgid.com/tools/charset-normalizer/
- Repository: https://github.com/jawah/charset_normalizer


## charset-normalizer: read text files of unknown encoding

charset-normalizer is a free Python library for text files whose character set nobody told you. It looks at the raw bytes and works out how to turn them into readable text. It also names the likely language and spots files that are not text at all. On short snippets its guess can be wrong, so known character sets should still come first.

### Where to use it
- Open uploads in any old encoding: People upload subtitles, price lists or exports from old programs; your app turns each file into readable text without asking which character set it uses.
- Narrow the guess when you know a shortlist: Your users are mostly in Western Europe, so you let it choose only between Windows-1252 and UTF-8 and avoid look-alike character sets.
- Swap out chardet in old code: An older script uses chardet to guess file encodings; you change one import line and keep everything else.
- Turn away files that are not text: A text import form rejects pictures or archives renamed to .txt before your code tries to read them.
- Check a folder of files from the terminal: Before an import, you run one command on old files and see the likely character set and language of each.
- Read scraped pages with no declared charset: A scraper meets pages that do not say which character set they use and still saves readable text from them. (idea, not from the official pages)

### How to start
- Install it into your project's Python environment.

```
pip install charset-normalizer -U
```

- Pass raw bytes or a file path and take the best match; str() gives the decoded text.

```
from charset_normalizer import from_bytes, from_path
# This is going to print out your sequence once properly decoded
print(str(from_bytes(my_byte_str).best()))
# You could also want the same from a file
print(str(from_path('./data/sample.1.ar.srt').best()))
```


### License
Free to use, change and sell as part of your product under the MIT license. Keep its copyright and license notice in copies you ship.

### Good to know
- It does not try to find the exact original character set, only one that gives the same readable text; Shift_JIS may come back as cp932.
- Guesses need enough text. On a few words it can pick a look-alike set; in our run a short French line came back with one wrong letter.
- Its docs call detection a last resort; if the file, page or header states its character set, use that.
- The guessed language is unreliable when a text mixes languages that share letters, such as English markup around Turkish text.
- It always keeps a pure Python version, so it installs where nothing can be compiled; faster built parts are added where available.

Checked 2026-11-10 against: https://github.com/jawah/charset_normalizer/blob/master/README.md, https://github.com/jawah/charset_normalizer/blob/master/LICENSE, https://pypi.org/pypi/charset-normalizer/3.5.2/json, https://charset-normalizer.readthedocs.io/en/latest/, https://charset-normalizer.readthedocs.io/en/latest/user/support.html, https://charset-normalizer.readthedocs.io/en/latest/user/getstarted.html, https://charset-normalizer.readthedocs.io/en/latest/user/advanced_search.html, https://charset-normalizer.readthedocs.io/en/latest/user/handling_result.html, https://charset-normalizer.readthedocs.io/en/latest/user/miscellaneous.html, https://charset-normalizer.readthedocs.io/en/latest/community/faq.html, https://charset-normalizer.readthedocs.io/en/latest/community/speedup.html

### Mistakes to avoid
- Don't: Trusting from_bytes(raw).best() on a short line of text without checks → Do: Use the declared charset when there is one, pass cp_isolation with the sets your users really have, or detect on more text (In our run a one-line French cp1252 text came back as cp1250 with à turned into ŕ; three lines or a shortlist fixed it.)
- Don't: str(from_bytes(raw).best()) without checking the result → Do: best = from_bytes(raw).best(); if best is None, reject the file or fall back to a known encoding (best() returns None when nothing fits, and str(None) would quietly give the text 'None'.)
- Don't: Detecting on the first 1,000 bytes of a large file to save time → Do: Pass the whole content (or a cut that ends on a full line) to from_bytes (A cut-off multi-byte character makes the guess fail; the docs say the package is fast enough without cutting.)
- Don't: best.output('cp1252') to save text back into a legacy encoding → Do: Keep the result as UTF-8 (the default of output()), or encode yourself with errors='strict' and handle failures (output() drops characters the target cannot hold, without replacing them or warning you.)
- Don't: Running the normalizer command with -r -f on a folder of originals → Do: Run it with -n first (writes new files) and keep the originals until you have checked them (-r replaces files and -f skips the question, so a wrong guess overwrites the only copy.)

### Questions
- Can I use it in a paid, closed-source app? Yes. It is MIT licensed; keep the copyright and license notice with the package.
- Is it a drop-in replacement for chardet? Mostly. It offers the same detect() function, and the docs say switching the import is usually enough.
- Can it repair text that already shows broken symbols? No. It works on raw bytes. For text that was already decoded wrongly, the README points to ftfy.
- Can I feed it only the first part of a big file to save time? Better not. A cut-off multi-byte character can make it fail, and the docs say it is fast enough on whole files.
- Is it maintained? Yes. Version 3.5.2 was uploaded to PyPI on 30 September 2026.

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
