Skip to main content

A Python package for detecting MIME types of local files and URLs

Project description

MIMEDetector

A Python package for detecting MIME types of local files and URLs. This package provides a simple and efficient way to determine the MIME type of both local files and remote URLs using various detection techniques.

Features

  • Detect MIME types of local files
  • Detect MIME types of remote URLs
  • Support for custom HTTP headers
  • Simple and intuitive API
  • Type hints for better development experience
  • Python 3.7+ support

Installation

You can install MIMEDetector using pip:

pip install mimedetector

Quick Start

from mimedetector import MIMEDetector

# Initialize the detector
detector = MIMEDetector()

# Check a local file
mime_type = detector.get_MIME("path/to/your/file.pdf")
print(f"Local file MIME type: {mime_type}")

# Check a remote URL
mime_type = detector.get_MIME("https://example.com/file.jpg")
print(f"Remote file MIME type: {mime_type}")

# Using custom headers for HTTP requests
headers = {
    "User-Agent": "Custom User Agent",
    "Accept": "*/*"
}
detector = MIMEDetector(headers=headers)
mime_type = detector.get_MIME("https://example.com/file.jpg")

API Reference

MIMEDetector

__init__(headers: Optional[Dict[str, str]] = None)

Initialize a new MIMEDetector instance.

  • headers: Optional dictionary of HTTP headers to use for remote requests

get_MIME(source_path: Union[str, pathlib.Path]) -> Optional[str]

Get the MIME type of a file or URL.

  • source_path: Path to local file or URL
  • Returns: MIME type string or None if unable to determine

check_file_location(path: Union[str, pathlib.Path]) -> str

Determine if the given path is a local file or remote URL.

  • path: Path to check
  • Returns: 'local' for local files, 'remote' for URLs, None for invalid paths

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Version History

  • 0.2.1
    • Added support for custom HTTP headers
    • Improved error handling
    • Updated documentation

Acknowledgments

  • Thanks to all contributors who have helped shape this project
  • Built with Python's excellent mimetypes and requests libraries

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

mimedetector-0.2.1.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mimedetector-0.2.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file mimedetector-0.2.1.tar.gz.

File metadata

  • Download URL: mimedetector-0.2.1.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for mimedetector-0.2.1.tar.gz
Algorithm Hash digest
SHA256 27f702291bdc07bcb9d89f0c9a67b4742fc3e8504e482c9479998d82fba9b325
MD5 ffaf436c4edcf655bb30a70fb46ba0aa
BLAKE2b-256 b3617b819914506cfd38a91e226aa066109666caa87f9636a1b806a24c194baa

See more details on using hashes here.

File details

Details for the file mimedetector-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: mimedetector-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for mimedetector-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 821a3670e0630fb39e911335270f22df7b397b67a9b8b939ea1718ac36040d88
MD5 34e8bdf4c5d8154f84a604107ead5836
BLAKE2b-256 926dfeec0f1dfcca5cb6e8613958f8801e369748ab14c6ab631d74674ece53c6

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