qmetrics.net

Python Magic

Python bindings for libmagic file type identification

File Management & SyncDesktop/CLI app

Python-magic exposes libmagic to Python so programs can guess file types from content headers. It wraps the same logic used by the Unix file command.

Overview

Python-magic is a Python interface to the libmagic file type identification library. Libmagic classifies files by inspecting their headers against a predefined list of types, matching what the Unix file command does on the command line.

A Magic class offers direct control, including choosing the magic database file and enabling character encoding detection. Identification via fromfile, frombuffer, and fromdescriptor uses a per-instance lock so those methods are safe across threads on one instance, though concurrent setparam changes or direct cookie access are not covered.

The package is a thin wrapper over the libmagic C library, which must be installed separately on the host. Installation notes in the documentation cover Debian and Ubuntu, macOS with Homebrew or MacPorts, Windows bitness issues, and pointing to non-standard library locations with environment variables.

Historically many reported issues trace to libmagic rather than the Python layer; the project documents compatibility between these bindings and libmagic’s own Python API via a compatibility layer.

Key features

  • Header-based file type detection
  • Magic class with custom database path
  • Optional character encoding detection
  • fromfile, frombuffer, fromdescriptor APIs
  • Per-instance locking for thread-safe reads
  • ctypes-based C library bindings
  • Combining libmagic flag options

Use cases

  • Detecting upload MIME types in web apps
  • Validating files before processing pipelines
  • Replacing shell file invocations from Python
  • Inspecting buffers without writing temp files

Similar software

Immich

Self-hosted photo and video library with mobile backup

Immich backs up, organizes, and browses personal photos and videos on hardware you run. Mobile and web clients share albums, search, and face grouping.

★ 120.3k⟳ todayAGPL-3.0
Open Source Alternative to:Apple PhotosGoogle Photos

LocalSend

Cross-platform local network file and message sharing app

LocalSend shares files and messages with nearby devices over your local network without internet. It uses HTTPS and works across desktop and mobile systems.

★ 101.2k⟳ 4 days agoApache-2.0
File Management & SyncDesktop/CLI app

Syncthing

Continuous file synchronization between your computers

Syncthing keeps folders in sync across two or more computers automatically. It prioritizes data safety, security, and ease of use for individual users.

★ 90.9k⟳ 2 days agoMPL-2.0
File Management & SyncDesktop/CLI app

Ventoy

Bootable USB loader for ISO and disk images

Ventoy prepares a USB drive so you can copy ISO, WIM, IMG, VHD, and EFI files and pick them from a boot menu without reformatting for each image.

★ 81.3k⟳ 4 days agoGPL-3.0
File Management & SyncDesktop/CLI app

Rclone

Command-line sync tool for cloud storage

Rclone copies and syncs files between local disks and many cloud backends. It mirrors familiar Unix-style file operations for remote storage.

★ 61.3k⟳ todayMIT
Backup & RecoveryDesktop/CLI app

Motrix

Full-featured desktop download manager

Motrix is a desktop download manager for HTTP, FTP, BitTorrent, magnet links, and related sources. A headless server variant adds a web UI and remote control over Docker.

★ 58.9k⟳ todayMIT · open core
File Management & SyncDesktop/CLI app
Open Source Alternative to:Internet Download Manager