Skip to main content

Check if a file or extension is text, and iterate over 300+ known text file types including source code, markup, data formats, and configuration files. Python port of text-extensions npm package.

Project description

Text Extensions

Python Version License Tests PyPI PyPI Downloads

Check if a file or extension is text, and iterate over 300+ known text file types including source code, markup, data formats, and configuration files. Python port of text-extensions npm package.

Features

  • Immutable collection of hundreds of known text file extensions
  • Fast membership checks using frozenset
  • Case-insensitive and dot-aware checks
  • Works for both extensions and full file paths
  • Supports dotfiles (e.g., .gitignore)
  • Zero dependencies, minimal overhead

Installation

pip install text-extensions

Or using uv:

uv add text-extensions

Usage

Check if an extension is text

from text_extensions import is_text_extension

is_text_extension("txt")      # True
is_text_extension(".py")      # True (dot-aware)
is_text_extension("JS")       # True (case-insensitive)
is_text_extension("png")      # False

Check if a file path has a text extension

from text_extensions import is_text_path

is_text_path("document.txt")              # True
is_text_path("/path/to/file.PY")          # True (case-insensitive)
is_text_path("script.js")                 # True
is_text_path("image.png")                 # False
is_text_path(".gitignore")                # True (dotfile support)

Access the list of text extensions

from text_extensions import TEXT_EXTENSIONS, TEXT_EXTENSIONS_LOWER

# TEXT_EXTENSIONS is a frozenset of all known text extensions
print(len(TEXT_EXTENSIONS))  # Number of supported extensions
"txt" in TEXT_EXTENSIONS     # True
"png" in TEXT_EXTENSIONS     # False

# TEXT_EXTENSIONS_LOWER contains all extensions in lowercase
# Useful for case-insensitive lookups without calling .lower() repeatedly
"TXT" in TEXT_EXTENSIONS_LOWER  # True (case-insensitive)

Supported Extensions

The package includes support for hundreds of text file extensions, including:

  • Source Code: py, js, ts, java, c, cpp, go, rs, rb, php, and more
  • Markup: html, xml, md, markdown, json, yaml, yml, and more
  • Stylesheets: css, scss, sass, less, styl, and more
  • Configuration: ini, conf, cfg, json, yaml, toml, and more
  • Data Formats: csv, tsv, json, xml, sql, and more
  • Documentation: txt, md, rst, tex, and more
  • Scripts: sh, bash, zsh, fish, bat, cmd, and more
  • And many more...

Credits

This package is a Python port of the text-extensions npm package by Sindre Sorhus.

Changelog

See CHANGELOG.md for a detailed list of changes and version history.

Contributing

Contributions are welcome! Please read our Contributing Guide for details on our code of conduct, development setup, and the process for submitting pull requests.

Support

If you find this library useful, please consider:

  • Starring the repository on GitHub to help others discover it.
  • 💖 Sponsoring to support ongoing maintenance and development.

Become a Sponsor on GitHub | Support on Patreon

License

MIT License - see LICENSE file for details.

Author

Y. Siva Sai Krishna

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

text_extensions-1.0.1.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

text_extensions-1.0.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file text_extensions-1.0.1.tar.gz.

File metadata

  • Download URL: text_extensions-1.0.1.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for text_extensions-1.0.1.tar.gz
Algorithm Hash digest
SHA256 394f9be5bca7e6443f3a22bb5363e4176913bcdae309a61f9d98123377c1a0f9
MD5 503edfdf766830fe4bce83ea851e0871
BLAKE2b-256 c7789d951142da04f670ac269513df6fc86adfbf4bc42d73df94e23c75b09405

See more details on using hashes here.

File details

Details for the file text_extensions-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: text_extensions-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for text_extensions-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b1cee6dc220f13d4cdc347158fd77d7db360d8ad8caf52b6a5e4ebc8002ade55
MD5 d717e7b04841d8051c84aa8164fbf42a
BLAKE2b-256 98b15376dd65e6bcd473b215c73ebbbe096edb0065beb6ed4bb6be3b7b45efc0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page