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

实例

简单的文件类型识别

importfiletypedefmain():

kind= filetype.guess('tests/fixtures/sample.jpg')if kind isNone: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读取文件类型_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读取Excel数据并根据列名取值

    一直想将自己接触到的东西梳理一遍,可就是迈不出第一步,希望从这篇总结开始不要再做行动的矮人了. 最近测试过程中需要用到python读取excel用例数据,于是去了解和学习了下xlrd库,这里只记录使用 ...

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

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

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

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

  8. python读取坐标文本文件_Python 实现文件读写、坐标寻址、查找替换功能

    读文件 打开文件(文件需要存在) #打开文件 f = open("data.txt","r") #设置文件对象 print(f)#文件句柄 f.close() ...

  9. python读取大文件目录_Python读取系统文件夹内所有文件并统计数量的方法

    大家先看一下Python os模块中的部分函数 python 路径相关的函数 os.listdir(dirname):列出dirname下的目录和文件 os.getcwd():获得当前工作目录 os. ...

最新文章

  1. 一劳永逸,iOS 自定义 ActionSheet 封装流程
  2. 收藏 | 图解Word2vec,读这一篇就够了!
  3. 文字如何实现完美UI?文本排版设计告诉你
  4. 在vSphere Client中启动虚拟机创建进程以及VMwareTools安装
  5. count(1),count(*),count(rowid)
  6. Logback MDC
  7. 论文笔记_S2D.38_2018-CVPR_DORN_用于单目深度估计的深度有序回归网络
  8. python图像边缘检测_python 简单图像处理(11) 空间域图像锐化(边缘检测)
  9. 本博客自排名300到264的各项数据变化
  10. python 爬取直播_python 斗鱼直播间爬取代码
  11. 潇洒郎: websockets 服务端设计:多线程执行async方法
  12. 超级记忆/图像数字记忆 110位数字图像转换表 31-40
  13. 常用的薪酬管理系统有哪些,薪酬管理需要具备哪些功能?
  14. Setup Time 、Hold Time、Setup check、Hold check,同步异步 及违例修复
  15. 解决了Office2007向程序发送命令时出现错误 的问题
  16. java-setBounds方法
  17. php实现报表拖拉拽,看!这款BI工具用拖拉拽的方式做报表
  18. 我的汉语名字叫东坤,可以帮我起一个读音相近的英语名字吗
  19. php word转化为html,php如何把word转换为html(这里使用COM)
  20. Android指纹解锁源码分析

热门文章

  1. 解决360浏览器自动填充的屎黄色背景的问题
  2. 养鱼的不一定是海王,也可能是运营人!
  3. 类微信APP,移动互联网第三大入口?
  4. lg gw880 qq2011 android beta4版,3G版OPhone旗舰手机 LG GW880网易评测
  5. 怎么在网上搜索redhat镜像下载不是百度盘就是官网下载?尤其是redhat7.6,除了百度盘怎么也找不到下载链接,官网更别说了
  6. 开源时代,看工业云如何玩转开源技术
  7. java计算机毕业设计宠物店管理系统MyBatis+系统+LW文档+源码+调试部署
  8. RuntimeError: implement_array_function method already has a docstring
  9. 校园跑腿小程序开发和设计
  10. [炉石]2017杭州第五周实力赛记录