Skip to main content

A library of helper methods for your Python project to get mime types and general file category

Project description

FTT Logo File Type Translator (FTT)

A library of helper methods for your Python project to get mime types and general file category

Releases

Available as a pypi package

1.1.8 - Updated sources, adds many modern file types and updates/eliminates some legacy mime types

1.1.7 - Updated sources, optimized generated code to be smaller and to be easier to diff future versions

1.1.5 - Updated sources, adds many modern file types and updates/eliminates some legacy mime types

1.1.3 - Updated sources, Notably the mime type for .js is now text/javascript instead of application/javascript according to the IANA standard specification

1.1.2 - Initial python release

Examples

Install

pip install fttlib

Import the library

from FTTLib import FTT

When you need to know the mime type of a file based on its extension.

mimeType = FTT.getMimeType("Path/To/My/File.doc")
print(mimeType)

mimeType = FTT.getMimeType("Path/To/My/File.docx")
print(mimeType)

>  application/msword
>  application/vnd.openxmlformats-officedocument.wordprocessingml.document

When you need to know the file type category of a file based on its extension.

category = FTT.getFileCategory("Path/To/My/File.docx")
print(category)

category = FTT.getFileCategory("Path/To/My/File.jpg")
print(category)

>  FileCategory.Document
>  FileCategory.Image

When you need to know the preferred file extension for a file based on its mime type.

extensions = FTT.getMimeTypeFileExtensions("text/csv")
print(extensions[0])

>  csv

Design

This library is designed along the following tenets:

  • No external dependencies
  • No file system access
  • Small memory footprint
  • Simple static methods (no extension methods and no instantiatable classes)
  • Case-insensitive
  • Portable - works in applications targeting any runtime

File Categories

File media types are broken down into relatively few categories. Sub-categories may be considered in a future release according to information on Wikipedia Here are the guidelines that determine a file's category

  • Archive: any file that can be extracted into several files
  • Audio: any file that can only contain an audio stream
  • Binary: any file that is unclassified or does not have a text representation
  • Code: any file that contains instructions that are compilable or machine-readable
  • Document: any file that is designed for conveying structured information between people
  • Image: any file that can only contain a single image or series of images
  • PDF: any file that is considered a document archive format
  • Presentation: any file that is designed for electronic presentations consisting of a series of separate pages or slides
  • Spreadsheet: any file in which data is arranged in rows and columns and can be manipulated and used in calculations
  • Text: any file that is not classified under another category and is not binary
  • Video: any file that is designed to be a container for a video stream

Known Limitations

  • Even though a mime type to file extension mapping is not necessarily one-to-one, the most common should be returned by the library
  • This library does not provide file sniffing capabilities - in other words, if you have a file and you want to verify the contents are of a specific type, look elsewhere. FTT only uses the file name with an extension. That capability may be added in a future release.
  • The only file categories presently considered are Archive, Audio, Binary, Code, Document, Image, PDF, Presentation, Spreadsheet, Text, and Video. Binary is the default if there is no match in the database.

Sources

While it is unrealistic to expect this library to provide a comprehensive list with all the file types the world has to offer, it would be nice if we could get close. Generally, if the file type is even remotely common, it is listed in one of the sources. You can submit a bug report for a file type that is missing or that you think should be added. You will have to include a reputable source as well.

Information sources for this library are provided through the following and in order of preference:

  1. http://www.iana.org/assignments/media-types/media-types.xhtml
  2. https://gitlab.freedesktop.org/xdg/shared-mime-info
  3. https://cdn.rawgit.com/jshttp/mime-db/master/db.json
  4. http://www.file-extensions.org/

Project details


Download files

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

Source Distribution

fttlib-1.1.8.tar.gz (63.4 kB view details)

Uploaded Source

Built Distribution

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

fttlib-1.1.8-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file fttlib-1.1.8.tar.gz.

File metadata

  • Download URL: fttlib-1.1.8.tar.gz
  • Upload date:
  • Size: 63.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.3

File hashes

Hashes for fttlib-1.1.8.tar.gz
Algorithm Hash digest
SHA256 bf2202b4aee45b29dc8eaff645b2daadce99589b7d7935040129fe6664443526
MD5 148b80a101497a30c52db2bd11162646
BLAKE2b-256 8d7e6605ed38a4b5511891024cf8b840103394aeff48dc6680ecf6f0e0b65a4b

See more details on using hashes here.

File details

Details for the file fttlib-1.1.8-py3-none-any.whl.

File metadata

  • Download URL: fttlib-1.1.8-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.3

File hashes

Hashes for fttlib-1.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 68eda04b37df4efdcfac0478d26e3c82e6cf9a3505785866a7c8b902dbdd9592
MD5 61c5ed7e3fcba3fdcd8d6ac0ff797038
BLAKE2b-256 e72ce731e44e37b77317e8e7d55572321be54e85877f762ec3cda6ad158417ed

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