Skip to main content

File type identification using libmagic

Project description

actrecipemagicfile (A CFFI fork of python-magic)

PyPI version

actrecipemagicfile is a Python interface to the libmagic file type identification library. libmagic identifies file types by checking their headers against a predefined list. This functionality is accessible from the command line using the Unix command file.

Changelog

[2024-12-04]

New: Added support for Mac Silicon (Python 3.10, 3.11).
New: Added support for Linux ARM (Python 3.10, 3.11, 3.12).

Usage

>>> import magicfile as magic
>>> magic.from_file("testdata/test.pdf")
'PDF document, version 1.2'
>>> magic.from_buffer(open("testdata/test.pdf").read(1024))
'PDF document, version 1.2'
>>> magic.from_file("testdata/test.pdf", mime=True)
'application/pdf'

There is also a Magic class that provides more direct control, including overriding the magic database file and turning on character encoding detection. This is not recommended for general use. In particular, it's not safe for sharing across multiple threads and will fail throw if this is attempted.

>>> f = magic.Magic(uncompress=True)
>>> f.from_file('testdata/test.gz')
'ASCII text (gzip compressed data, was "test", last modified: Sat Jun 28
21:32:52 2008, from Unix)'

You can also combine the flag options:

>>> f = magic.Magic(mime=True, uncompress=True)
>>> f.from_file('testdata/test.gz')
'text/plain'

License

actrecipemagicfile is distributed under the MIT license. See the included LICENSE file for details.

Notes:

  • This package is primarily used in an internal project.
  • Support for Mac Silicon and Linux ARM is effective from 2024-12-04.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

actrecipemagicfile-0.4.34-cp314-cp314-macosx_10_15_x86_64.macosx_14_0_arm64.whl (407.2 kB view details)

Uploaded CPython 3.14macOS 10.15+ x86-64macOS 14.0+ ARM64

actrecipemagicfile-0.4.34-cp313-cp313-macosx_10_13_x86_64.macosx_14_0_arm64.whl (407.0 kB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64macOS 14.0+ ARM64

actrecipemagicfile-0.4.34-cp312-cp312-macosx_10_13_x86_64.macosx_14_0_arm64.whl (407.0 kB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64macOS 14.0+ ARM64

actrecipemagicfile-0.4.34-cp311-cp311-macosx_10_9_x86_64.macosx_14_0_arm64.whl (407.1 kB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64macOS 14.0+ ARM64

actrecipemagicfile-0.4.34-cp310-cp310-macosx_10_9_x86_64.macosx_14_0_arm64.whl (407.1 kB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64macOS 14.0+ ARM64

File details

Details for the file actrecipemagicfile-0.4.34-cp314-cp314-macosx_10_15_x86_64.macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for actrecipemagicfile-0.4.34-cp314-cp314-macosx_10_15_x86_64.macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f5149e71217406769469a9523d08985498ce4beaeac966f570c9c9032bf75ca7
MD5 c009cb42ff136d86c4e77a2daa7d7c31
BLAKE2b-256 a1a8b57c0a241f96988ccd5c0dbb273c9a3d60b1ddbe1db787ebb9b3f123a80e

See more details on using hashes here.

File details

Details for the file actrecipemagicfile-0.4.34-cp313-cp313-macosx_10_13_x86_64.macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for actrecipemagicfile-0.4.34-cp313-cp313-macosx_10_13_x86_64.macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 d0dc6e6c4683bd8ddac915f728d4ab709d1a4321274fc88abb72a53ceec2542e
MD5 7fc93aba2fb726b0cf2901f73b626df4
BLAKE2b-256 4d9c140eadd31854ae0d22e4fb1952b76020d79d1ce67cf359de3670fa209ef7

See more details on using hashes here.

File details

Details for the file actrecipemagicfile-0.4.34-cp312-cp312-macosx_10_13_x86_64.macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for actrecipemagicfile-0.4.34-cp312-cp312-macosx_10_13_x86_64.macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c788c667695030a5e5552cfee7a10f6f1d2d503c4df0964a42141e3164f09627
MD5 89ecdc295fbf2080e31f573b79438a7d
BLAKE2b-256 b8dd392c356cce9f4cc5bee6214b0a0ead06c72781ac89f14c18edc26d8a9b51

See more details on using hashes here.

File details

Details for the file actrecipemagicfile-0.4.34-cp311-cp311-macosx_10_9_x86_64.macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for actrecipemagicfile-0.4.34-cp311-cp311-macosx_10_9_x86_64.macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 2ea1340c547b5de9a39052e28c7a7d449b04652817d7c0bf6a3b2d85ee24faee
MD5 f2d23e85b3c6a499549eb0233cf3e178
BLAKE2b-256 518a7db9f19a2fe34d823cbd39f45cfe9df2c9c3c3b21fd7d9e6170f76d83de9

See more details on using hashes here.

File details

Details for the file actrecipemagicfile-0.4.34-cp310-cp310-macosx_10_9_x86_64.macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for actrecipemagicfile-0.4.34-cp310-cp310-macosx_10_9_x86_64.macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 ee6ec522ea1cfadad148892055842187c43e19dd4855e85fe159a2684650e802
MD5 98d9b79c56de125b63db78251039daeb
BLAKE2b-256 0814845114159bd471bf8db827e456640be188a94d564dbaa221eed8bcde34b1

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