Lightweight Python library to detect common file formats by inspecting signatures and heuristics.
Project description
Identifile
Lightweight Python library to detect common file formats (compression, archive, and columnar storage) by inspecting file signatures and heuristics.
Project
- Name: Identifile
- Version: 2.0.0
- Authors: Sai Niranjan Chitturi, Leela Sai Surya Veer Pedarla, Bhargav Dasari, Kavya Sri Punna, Vinay Appari, Chandralekha Alluri, Eknath Narravula, Pavan, Divya, OpenAI, xAI
- License: MIT
This repository contains a small utility to sniff file formats from a file path or a binary stream. It recognizes formats such as gzip, zstd, bzip2, lz4, xz, ZIP/7z/tar, Snappy variants, Brotli (heuristic), Parquet and ORC.
Features
- Signature-based detection for common compressed and archived formats.
- Columnar format detection for Parquet and ORC.
- Work with file paths (
sniff_format) or file-like binary streams (sniff_stream). - Extension hints for formats that lack headers (e.g. raw Snappy files).
- Small and easily extensible signature table. Add custom signatures with
add_signature().
Files
Identifile.py— Main implementation (definesIdentifile,sniff_format,sniff_stream,add_signature, andSIGNATURES).testFormat.py— Unit tests covering detection logic and edge-cases usingunittest.
Usage
Example (detect from file path):
from Identifile import sniff_format
result = sniff_format('example.gz')
print(result.summary())
Example (detect from stream):
from Identifile import sniff_stream
from io import BytesIO
stream = BytesIO(b'\x1f\x8b' + b'\x00'*100)
result = sniff_stream(stream)
print(result.format, result.confidence, result.evidence)
Add a custom signature:
from Identifile import add_signature
add_signature('myfmt', {'start': [b'\xAA\xBB'], 'evidence': 'My custom format.'})
API Summary
- Identifile(format: str, confidence: float, evidence: str, extra: dict)
- Methods:
is_known(),is_compressed(),is_archive(),is_columnar(),summary(),metadata()
- Methods:
- sniff_format(file_path: str, head_n: int = 64, tail_n: int = 64, use_extension_hint: bool = True) -> Identifile
- sniff_stream(stream: BinaryIO, head_n: int = 64, tail_n: int = 64, buffer_non_seekable: bool = True, extension_hint: Optional[str] = None) -> Identifile
- add_signature(format_name: str, signature: dict, overwrite: bool = False)
Running Tests
The project uses Python's built-in unittest. From the project root run:
python -m unittest testFormat.py
Notes:
- Tests in
testFormat.pyreferenceIdentifilemodule and exercise both file and stream-based detection. Ensure the working directory includesIdentifile.py.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Authors and Contributors
- Your Name your.email@example.com — primary author. Update
Identifile.pyto set__author__and replace this entry. - Tests and example usage were authored based on the implementation in
testFormat.py.
Contributions are welcome. Please open issues or pull requests with improvements, additional signatures, or bug fixes.
Contributing
- Fork the repository, create a feature branch, add tests for new behavior, and open a pull request.
- Keep signatures small and add clear evidence strings.
Changes
- v0.1.2 — initial public snapshot (version string found in
Identifile.py).
If you'd like, I can also update the __author__ value in Identifile.py to match a specific name/email and add a short example script. Tell me how you'd like the author line to read.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file identifile-1.1.0.tar.gz.
File metadata
- Download URL: identifile-1.1.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40d5d3e65f638905d596ec93a69d6c5a683af18cc03a32fc06072af80e1ca8bb
|
|
| MD5 |
be8ed27fbbd97e812a9bddb830f7929c
|
|
| BLAKE2b-256 |
fc706a77658bdb9874d0681dfd5c1386d358f26bb9d31e10fb284efe0657d588
|
File details
Details for the file identifile-1.1.0-py2.py3-none-any.whl.
File metadata
- Download URL: identifile-1.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c1d7d3da3fdd39695d23df8e47344170eae99dd23b93032575f9ee55a65619f
|
|
| MD5 |
627c93d3574c084ea2df0fe856ed20ee
|
|
| BLAKE2b-256 |
7b775072b28be6120973639bdd7cd7a039379b5d1cab4bb3259681f59d0c1660
|