pip install magika
!magika **/duckdb/data
pip install python-magic
mac 和Windows用户还需要额外安装libmagic
file 在Linux下和macOS下为系统自带命令,Windows下需要自行安装了
import magic
magic.from_file("testdata/test.pdf")
'PDF document, version 1.2'
# recommend using at least the first 2048 bytes, as less can produce incorrect identification
magic.from_buffer(open("testdata/test.pdf", "rb").read(2048))
'PDF document, version 1.2'
magic.from_file("testdata/test.pdf", mime=True)
'application/pdf'
python 文件类型识别库 magika
python 文件类型识别库 magika的用法