{"id":21338,"library":"file-magic","title":"file-magic","description":"Python front end for libmagic(3) — uses ctypes to wrap libmagic for file type detection. Current version 0.4.1, last released 2016; requires libmagic (system library). Unmaintained; prefer `python-magic` for active development.","status":"deprecated","version":"0.4.1","language":"python","source_language":"en","source_url":"https://github.com/file/file","tags":["file-magic","mime-type","libmagic","file detection"],"install":[{"cmd":"pip install file-magic","lang":"bash","label":"PyPI install"}],"dependencies":[{"reason":"System library (libmagic) must be installed; Linux: apt-get install libmagic1, macOS: brew install libmagic","package":"libmagic","optional":false}],"imports":[{"note":"Top-level import; no submodule needed.","wrong":"","symbol":"magic","correct":"import magic"}],"quickstart":{"code":"import magic\nm = magic.open(magic.MAGIC_NONE)\nm.load()\ntype_ = m.file('/path/to/file')  # e.g., 'ASCII text'\nprint(type_)\n","lang":"python","description":"Basic usage: create a magic cookie, load magic database, detect file type."},"warnings":[{"fix":"Use `python-magic` for new projects.","message":"`file-magic` is unmaintained (last release 2016). Prefer `pip install python-magic` instead, which has a similar API and is actively maintained.","severity":"gotcha","affected_versions":"all"},{"fix":"Install libmagic (e.g., apt-get install libmagic1 on Debian/Ubuntu).","message":"Requires system libmagic installed. If missing, get an OSError or ImportError.","severity":"gotcha","affected_versions":"all"},{"fix":"Consider using `python-magic-bin` or `python-magic` with appropriate binary.","message":"On Windows, libmagic is not preinstalled; need to bundle DLL or use alternative.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'0.4.1':21 '2016':24 '3':9 'activ':35 'ctype':11 'current':19 'detect':18,45 'develop':36 'end':6 'file':2,16,38,44 'file-mag':1,37 'front':5 'last':22 'libmag':8,14,26,43 'librari':28 'magic':3,33,39 'mime':41 'mime-typ':40 'prefer':30 'python':4,32 'python-mag':31 'releas':23 'requir':25 'system':27 'type':17,42 'unmaintain':29 'use':10 'version':20 'wrap':13","created_at":"2026-04-27T16:59:22.997591+00:00","updated_at":"2026-04-27T16:59:22.997591+00:00","problems":[{"fix":"Uninstall both and reinstall only one: `pip uninstall file-magic python-magic python-magic-bin` then `pip install python-magic`.","cause":"Both `file-magic` and `python-magic` create a module named `magic`. If both are installed, import may fail or wrong version used.","error":"ImportError: No module named magic"},{"fix":"Install libmagic: on Linux `sudo apt-get install libmagic1` (or equivalent), on macOS `brew install libmagic`.","cause":"System library libmagic is missing.","error":"OSError: libmagic not found"},{"fix":"Encode path if needed: `m.file(bytes(path, 'utf-8'))` or ensure string path works (usual).","cause":"In Python 3, file path must be bytes or string; often happens when passing string to .file() where lib expects bytes.","error":"TypeError: a bytes-like object is required, not 'str'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.4.1","cli_name":"","cli_version":null,"type":"library","homepage":"https://https://darwinsys.com/file/","github":null,"docs":null,"changelog":null,"pypi":"https://pypi.org/project/file-magic/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}