Skip to main content

Python port of text-extensions npm package. 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.

Project description

Text Extensions

Python Version License Tests

Python port of text-extensions npm package. 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.

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.

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.0.tar.gz (17.2 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.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: text_extensions-1.0.0.tar.gz
  • Upload date:
  • Size: 17.2 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.0.tar.gz
Algorithm Hash digest
SHA256 b90bb00dd669c2e4e4137d92e11da85c9a2f25e767021df4f9c0427d731c6daa
MD5 57ec8f783d14196cd8db3dbc2489d1e7
BLAKE2b-256 fcc002e860f8cfeaf6c3631249341b36a176b1f147e134dbbd05aa7d93051491

See more details on using hashes here.

File details

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

File metadata

  • Download URL: text_extensions-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0ae7da11b77ab0ce94cec0442c233a24bf5cb5899b39a9097f782594550a85b4
MD5 ae2b033c92d6528e3248ffd82356564d
BLAKE2b-256 56e5d14f44ceb8958302c7243a2ba8a69fb4e6691e79e32f3ff5b31a9e31e186

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