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.35-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.35-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.35-cp312-cp312-macosx_10_13_x86_64.macosx_14_0_arm64.whl (408.4 kB view details)

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

actrecipemagicfile-0.4.35-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.35-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.35-cp314-cp314-macosx_10_15_x86_64.macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for actrecipemagicfile-0.4.35-cp314-cp314-macosx_10_15_x86_64.macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9398bd5bf5fbd9eed7f6ce242a55fd9487bd927857d93cbb16e3d73c9958f111
MD5 16bcb8df08ad06f481d689c7b6acafe9
BLAKE2b-256 62673d7a6c146bf7078dca9ec4d05f53f38225f9c0f7a64624e69f2b6c3baac8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for actrecipemagicfile-0.4.35-cp313-cp313-macosx_10_13_x86_64.macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5fff8863f6d905c7a8a4450878e5736fa60d6d066f46b912f762156e6e6a0a46
MD5 65f9c275ad95924bd24a144565ea69e9
BLAKE2b-256 03acdfad0f6028af9f3c12e004e3ad7eb0b183923b1af6dd7d646a3455df3c7d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for actrecipemagicfile-0.4.35-cp312-cp312-macosx_10_13_x86_64.macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 1a954c2a48dd1d075499c4fda13d2674818e45991a0421214db79b4b51588fb7
MD5 0fd4d6160b091684493c0cfd888c56dd
BLAKE2b-256 7765fa34708f3d86f744b3a20ef655aeecc94b6b862159fed44df75c7f102f21

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for actrecipemagicfile-0.4.35-cp311-cp311-macosx_10_9_x86_64.macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 28c0c66cb50936018ed0717ed689e797e6eed2cee5bf2838e97e4e2d774259c3
MD5 6f63d51f3b72f71dcd68ceeb011edbda
BLAKE2b-256 7a1f6302782382bec6c10061860328645ddb80800256b7875c390b1c91e31149

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for actrecipemagicfile-0.4.35-cp310-cp310-macosx_10_9_x86_64.macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 c4084710d922031589c3380f003e6e8a9bfd779a71c19ae3f59c59af638746fb
MD5 89c8818b8ba5e7066a456401b14ccd0b
BLAKE2b-256 1142f4e3e1b36c0c2d3efbb8e4e1b872e34df8e008e9c12bdf6d8987d280f1c3

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