A Python package to get file extensions from MIME types, with support for additional formats.
Project description
Mimetypes Extension 🗃️🔎
A Python package to get file extensions from MIME types, with support for additional formats not covered by Python's built-in mimetypes module.
Features
- Extended MIME Type Support: Adds support for many MIME types not included in Python's standard
mimetypesmodule. - Simple API: Provides easy-to-use functions like
get_extensionandget_extensions. - Case Insensitive: Handles MIME types in any case (e.g.,
image/jpeg,IMAGE/JPEG). - Multiple Extensions: Returns all possible file extensions for a given MIME type.
Installation
You can install the package via pip:
pip install mimetypes-extension
Usage
Get a Single File Extension
Use get_extension to get the most common file extension for a given MIME type:
from mime_ext import get_extension
# Get the extension for a MIME type
extension = get_extension("image/jpeg")
print(extension) # Output: .jpg
Get All File Extensions
Use get_extensions to get all possible file extensions for a given MIME type:
from mime_ext import get_extensions
# Get all extensions for a MIME type
extensions = get_extensions("text/javascript")
print(extensions) # Output: ['.js', '.mjs']
Handle Unknown MIME Types
If the MIME type is unknown, the functions return an .bin as a fallback or list:
unknown_extension = get_extension("unknown/type")
print(unknown_extension) # Output: ".bin"
unknown_extensions = get_extensions("unknown/type")
print(unknown_extensions) # Output: []
Supported MIME Types
The package supports a wide range of MIME types, including but not limited to:
- Text:
text/plain,text/html,text/css,text/javascript, etc. - Images:
image/jpeg,image/png,image/gif,image/webp, etc. - Audio:
audio/mpeg,audio/ogg,audio/wav, etc. - Video:
video/mp4,video/quicktime,video/webm, etc. - Archives:
application/zip,application/gzip,application/x-tar, etc. - Documents:
application/pdf,application/json,application/xml, etc.
For a full list of supported MIME types, check the source code.
Contributing
Contributions are welcome! If you'd like to add support for more MIME types or improve the package, follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Make your changes and write tests if applicable.
- Submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgments
- Inspired by Python's built-in
mimetypesmodule. - Thanks to me only!
Support
If you find this package useful, please consider giving it a ⭐️ on GitHub or supporting the developer.
Happy coding! 🚀
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 mimetypes_extension-0.1.0.tar.gz.
File metadata
- Download URL: mimetypes_extension-0.1.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
915f504601c913f2e1250e0f3638dd4a8e23ecd6dcda9bb6b0df4bee45ffcda2
|
|
| MD5 |
d411caf8b18f5e9616ef95460995b59a
|
|
| BLAKE2b-256 |
62722e88960e8d81d6dec0104d94289272fbd141dd6d7447186d754b47f2563e
|
File details
Details for the file mimetypes_extension-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mimetypes_extension-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2eba4e5f3d583d1d94cb9df6d28bd00d932a62ac3d7ab666cecbc68d78b71ae
|
|
| MD5 |
001cc73b67491fb128d89cf5565e33f8
|
|
| BLAKE2b-256 |
3ce7fc79d161b7be179d0aeea8d5d24be146a3fc307e8d4ff40500b35452c33f
|