filetype.py

Small and dependency free Python package to infer file type and MIME type checking the magic numbers signature of a file or buffer.

This is a Python port from filetype Go package. Works in Python +3 .

一个小巧自由开放Python开发包,主要用来获得文件类型。包要求Python 3.+

功能特色

•简单友好的API
•支持宽范围文件类型
•提供文件扩展名和MIME类型判断
•文件的MIME类型扩展新增
•通过文件(图像、视频、音频…)简单分析
•可插拔:添加新的自定义类型的匹配
•快,即使处理大文件
•只需要前261个字节表示的最大文件头,这样你就可以通过一个单字节
•依赖自由(只是Python代码,没有C的扩展,没有libmagic绑定)
•跨平台文件识别

安装

pip install filetype

API

详情请查看 annotated API reference .

实例

简单的文件类型识别

复制代码
import filetype

def main():
kind = filetype.guess(‘tests/fixtures/sample.jpg’)
if kind is None:
print(‘Cannot guess file type!’)
return

print(‘File extension: %s’ % kind.extension)
print(‘File MIME type: %s’ % kind.mime)

if name == ‘main’:
main()
复制代码

复制代码
支持类型

图片

• jpg – image/jpeg
• png – image/png
• gif – image/gif
• webp – image/webp
• cr2 – image/x-canon-cr2
• tif – image/tiff
• bmp – image/bmp
• jxr – image/vnd.ms-photo
• psd – image/vnd.adobe.photoshop
• ico – image/x-icon

视频

• mp4 – video/mp4
• m4v – video/x-m4v
• mkv – video/x-matroska
• webm – video/webm
• mov – video/quicktime
• avi – video/x-msvideo
• wmv – video/x-ms-wmv
• mpg – video/mpeg
• flv – video/x-flv

音频

• mid – audio/midi
• mp3 – audio/mpeg
• m4a – audio/m4a
• ogg – audio/ogg
• flac – audio/x-flac
• wav – audio/x-wav
• amr – audio/amr

资料库

• epub – application/epub+zip
• zip – application/zip
• tar – application/x-tar
• rar – application/x-rar-compressed
• gz – application/gzip
• bz2 – application/x-bzip2
• 7z – application/x-7z-compressed
• xz – application/x-xz
• pdf – application/pdf
• exe – application/x-msdownload
• swf – application/x-shockwave-flash
• rtf – application/rtf
• eot – application/octet-stream
• ps – application/postscript
• sqlite – application/x-sqlite3
• nes – application/x-nintendo-nes-rom
• crx – application/x-google-chrome-extension
• cab – application/vnd.ms-cab-compressed
• deb – application/x-deb
• ar – application/x-unix-archive
• Z – application/x-compress
• lz – application/x-lzip

字体

• woff – application/font-woff
• woff2 – application/font-woff
• ttf – application/font-sfnt
• otf – application/font-sfnt

Python filetype包精确判断文件类相关推荐

  1. python获取文件后缀_Python使用filetype精确判断文件类型 (文件类型获取)

    filetype.py Small and dependency free Python package to infer file type and MIME type checking the m ...

  2. python如何区分文件类型_Python使用filetype精确判断文件类型

    filetype.py Small and dependency free Python package to infer file type and MIME type checking the m ...

  3. python判断图片类型_Python使用filetype精确判断文件类型

    filetype.py Small and dependency free Python package to infer file type and MIME type checking the m ...

  4. python脚本文件格式_Python使用filetype精确判断文件类型

    filetype.py Small and dependency free Python package to infer file type and MIME type checking the m ...

  5. python读取文件类型_Python使用filetype精确判断文件类型 (文件类型获取)

    filetype.py Small and dependency free Python package to infer file type and MIME type checking the m ...

  6. Python库 使用filetype精确判断文件类型

    filetype判断文件类型 作用 一个小巧自由开放Python开发包,主要用来获得文件类型. 支持版本: python2/python3 安装: pip install filetype 功能特色 ...

  7. python如何区分文件类型_Python库 使用filetype精确判断文件类型

    一个小巧自由开放Python开发包,主要用来获得文件类型. filetype支持版本: python2/python3 filetype安装: pip install filetype filetyp ...

  8. python文件的两种类型进制文件,Python之基于十六进制判断文件类型

    #!/usr/bin/env python#-*- coding: utf-8 -*-#@Author : suk importstructfrom io importBytesIO#支持文件类型#用 ...

  9. python os.path.exists判断文件或文件夹是否存在

    import os#判断文件夹是否存在 dir = os.path.exists('C:\\Users\\Desktop') print('dir:', dir)#判断文件是否存在 file = os ...

最新文章

  1. 【已解决】wepy中使用分包加载报错
  2. 个人博客(前端菜鸡)持续开发中,可前往 欢迎访问. www.amayaliu.cn
  3. 2020-11-23(dll注入方法)
  4. windows7开启虚拟wifi和虚拟无线AP的方法
  5. linux基础学习(十)
  6. UliPad 初体验----python 开发利器
  7. [eclipse]Syntax error on token ;,{ expected after this token
  8. 服务器启动将字典加载到内存中@PostConstruct
  9. docker 安装hadoop
  10. Flutter实战一Flutter聊天应用(七)
  11. Selenium下载与安装
  12. 阿里云盘——新的屠龙勇士?
  13. Hive提取身份证号中年龄和性别
  14. python最简单的爬取邮箱地址_python小脚本-提取邮箱
  15. 初创企业融资PPT模板
  16. 笔记本分享热点wifi给手机上网
  17. 关于系统之间的单点登陆对接
  18. Spark源码走读概述
  19. 了解Oracle RAC Brain Split Resolution集群脑裂协议
  20. layer.msg 延迟几秒跳转页面

热门文章

  1. python:小游戏“贪吃蛇大作战“!
  2. bowtie和bwa比对,reads mapping contig
  3. 许多研究生的一个通病:对导师过度依赖!
  4. Docker 安装Jenkins + Python + Allure + JDK
  5. 08-ESP8266按钮处理
  6. 三国杀移动版显示服务器忙,三国杀移动版
  7. Android实现音乐播放器,Service后台播放Notification控制播放状态
  8. C++和Java怎么选择,哪个好找工作?
  9. 虚拟化技术 — QEMU-KVM 基于内核的虚拟机
  10. 万圣节屌丝逆袭白富美攻略