Skip to main content

Check if a file or extension is binary, and iterate over 250+ known binary file types including images, videos, archives, and executables. Python port of binary-extensions npm package.

Project description

Binary Extensions

Python Version License Tests PyPI PyPI Downloads

Check if a file or extension is binary, and iterate over 250+ known binary file types including images, videos, archives, and executables. Python port of binary-extensions npm package.

Features

  • Immutable collection of hundreds of known binary 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., .DS_Store)
  • Zero dependencies, minimal overhead

Installation

pip install binary-extensions

Or using uv:

uv add binary-extensions

Usage

Check if an extension is binary

from binary_extensions import is_binary_extension

is_binary_extension("png")      # True
is_binary_extension(".jpg")     # True (dot-aware)
is_binary_extension("PDF")      # True (case-insensitive)
is_binary_extension("txt")      # False

Check if a file path has a binary extension

from binary_extensions import is_binary_path

is_binary_path("image.png")                    # True
is_binary_path("/path/to/file.JPG")            # True (case-insensitive)
is_binary_path("document.pdf")                 # True
is_binary_path("document.txt")                 # False
is_binary_path(".DS_Store")                     # True (dotfile support)

Access the list of binary extensions

from binary_extensions import BINARY_EXTENSIONS, BINARY_EXTENSIONS_LOWER

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

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

Supported Extensions

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

  • Images: png, jpg, gif, bmp, webp, svg, ico, and more
  • Audio: mp3, wav, flac, aac, ogg, and more
  • Video: mp4, avi, mkv, mov, webm, and more
  • Archives: zip, tar, gz, 7z, rar, and more
  • Documents: pdf, doc, docx, xls, xlsx, ppt, pptx, and more
  • Executables: exe, dll, so, dmg, appimage, and more
  • Fonts: ttf, otf, woff, woff2, and more
  • And many more...

Credits

This package is a Python port of the binary-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

binary_extensions-1.0.1.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.

binary_extensions-1.0.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: binary_extensions-1.0.1.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 binary_extensions-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6db01c1c5697ef9fd657c5489955c972c7089b3e533ed1330e566a23bd601994
MD5 7d4faaca56d0b603cb5de06bd43105c6
BLAKE2b-256 fa1cd6e2ee02a43449f416c6044e4599366257624d52279fa1216ddd0a25b94f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: binary_extensions-1.0.1-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 binary_extensions-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b8b129bc12ffb2029c926b1af5da86ecbdc317b7f644b15ac481f139ffb59506
MD5 b56d9f22650e4ab5ad6f0cfe419b60d6
BLAKE2b-256 b9240357d114522e7c6ff1c5102e3ef4146b3f3cb82da5ff05470bac4bcb08fe

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