https://github.com/dobizz/filext
Python library to identify file type based on its file signature
https://github.com/dobizz/filext
files python utilities
Last synced: 6 months ago
JSON representation
Python library to identify file type based on its file signature
- Host: GitHub
- URL: https://github.com/dobizz/filext
- Owner: dobizz
- License: mit
- Created: 2022-09-24T17:37:15.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-04-13T00:55:55.000Z (about 1 year ago)
- Last Synced: 2025-11-04T10:09:35.801Z (8 months ago)
- Topics: files, python, utilities
- Language: Python
- Homepage: https://pypi.org/project/filext/
- Size: 135 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# filext
Python library to identify file type based on its file signature
### Installation
```
pip install filext
```
### Usage
If the category of the file is not certain, you may use `whatfile` but is a little slower
```python
from filext import whatfile
file_path = "./tests/files/document.pdf"
# pass file as path str
file_type = whatfile(file_path)
with open(filepath, "rb") as file:
# pass file as bytes
file_type = whatfile(file.read())
```
If the category of the file is known, you may use the function for that category instead.
```python
from filext import whatdoc
file_path = "./tests/files/document.pdf"
# pass file as path str
file_type = whatdoc(file_path)
with open(filepath, "rb") as file:
# pass file as bytes
file_type = whatdoc(file.read())
```
### Supported File Types
#### Documents
- [x] PDF
- [x] DOC
- [x] PPT
- [x] XLS
- [x] DOCX
- [x] PPTX
- [x] XLSX
#### Images
- [x] BMP
- [x] GIF
- [x] HEIC
- [x] JPG
- [x] PNG
- [x] TIF