python-magic

Python interface to libmagic for file type identification.

EstablishedOpen SourceLow lock-in

Pricing

Free tier

Flat rate

Adoption

Stable

License

Open Source

Data freshness

Aging · Jun 8, 2026

Overview

What is python-magic?

Provides a Python interface to the libmagic library, enabling developers to identify file types based on their content. This tool is essential for applications that need to handle various file formats and ensure correct processing.

Key differentiator

python-magic offers precise and reliable file type identification through its Python interface to libmagic, making it an indispensable tool for developers dealing with diverse file formats.

Capability profile

Capability Radar

Ease of StartEcosystemValueMaturityFlexibilityScale Ready

Honest assessment

Strengths & Weaknesses

↑ Strengths

Identifies file types based on content, not just filename extensions.medium

Wraps the libmagic library for easy integration into Python projects.medium

Supports a wide range of file formats and signatures.medium

↓ Weaknesses

Limited support for non-standard file typeshigh

Relies on libmagic, which may not recognize less common or proprietary file formats.

Performance overhead when processing large filesmedium

Analyzing the content of very large files can be slow and resource-intensive.

Depends on libmagic, which may not be up-to-date with new file typeshigh

libmagic signatures are updated periodically, potentially missing newer or less common file formats.

Configuration complexity for custom magic filesmedium

Setting up and maintaining custom magic files requires detailed knowledge of the libmagic format and structure.

Fit analysis

Who is it for?

✓ Best for

Developers working on file processing systems who need accurate file type identification.

Security analysts needing to identify and categorize various file types for analysis.

✕ Not a fit for

Applications requiring real-time, high-performance file type detection in extremely large datasets.

Projects that require a web-based UI or cloud-hosted service for file type identification.

Cost structure

Pricing

Free Tier

Available

Open source — free to use

Starts at

$0

Model

Flat rate

Enterprise

None

Performance benchmarks

How Fast Is It?

Ecosystem

Relationships

Next step

Get Started with python-magic

Step-by-step setup guide with code examples and common gotchas.

View Setup Guide →