content-types 0.2.2__tar.gz → 0.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,144 @@
1
+ Metadata-Version: 2.4
2
+ Name: content-types
3
+ Version: 0.2.3
4
+ Summary: A library to map file extensions to content types and vice versa.
5
+ Project-URL: Homepage, https://github.com/mikeckennedy/content-types
6
+ Project-URL: Bug Reports, https://github.com/mikeckennedy/content-types/issues
7
+ Project-URL: Source, https://github.com/mikeckennedy/content-types
8
+ Author-email: Michael Kennedy <mikeckennedy@gmail.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: content-type,file extensions,mapping,mime
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Topic :: Internet :: WWW/HTTP
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: <=3.14,>=3.10
23
+ Description-Content-Type: text/markdown
24
+
25
+
26
+ # content-types 🗃️🔎
27
+
28
+ A Python library to map file extensions to MIME types.
29
+ It also provides a CLI for quick lookups right from your terminal.
30
+ If no known mapping is found, the tool returns `application/octet-stream`.
31
+
32
+ Unlike other libraries, this one does **not** try to access the file
33
+ or parse the bytes of the file or stream. It just looks at the extension
34
+ which is valuable when you don't have access to the file directly.
35
+ For example, you know the filename but it is stored in s3 and you don't want
36
+ to download it just to fully inspect the file.
37
+
38
+ Why not just use Python's built-in `mimetypes`? Or the excellent `python-magic` package? See below.
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ uv pip install content-types
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ ```python
49
+ import content_types
50
+
51
+ # Forward lookup: filename -> MIME type
52
+ the_type = content_types.get_content_type("example.jpg")
53
+ print(the_type) # "image/jpeg"
54
+
55
+ # For very common files, you have shortcuts:
56
+ print(f'Content-Type for webp is {content_types.webp}.')
57
+ # Content-Type for webp is image/webp.
58
+ ```
59
+
60
+ ## CLI
61
+
62
+ To use the library as a CLI tool, just install it with **uv** or **pipx**.
63
+
64
+ ```bash
65
+ uv tool install content-types
66
+ ```
67
+
68
+ Now it will be available machine-wide.
69
+
70
+ ```bash
71
+ content-types example.jpg
72
+
73
+ # Outputs image/jpeg
74
+ ```
75
+
76
+ ## More correct than Python's `mimetypes`
77
+
78
+ When I first learned about Python's mimetypes module, I thought it was exactly what I need. However,
79
+ it doesn't have all the MIME types. And, it recommends deprecated, out-of-date answers for very obvious types.
80
+
81
+ For example, mimetypes has `.xml` as text/xml where it should be `application/xml`
82
+ (see [MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/MIME_types/Common_types)).
83
+
84
+ And mimetypes is missing important types such as:
85
+
86
+ - .m4v -> video/mp4
87
+ - .tgz -> application/gzip
88
+ - .flac -> audio/flac
89
+ - .epub -> application/epub+zip
90
+ - ...
91
+
92
+ Here is a full comparison found by running `samples/compare_to_builtin.py`:
93
+
94
+ ```text
95
+ There are 5 types where mimetypes and content-types disagree
96
+
97
+ mimetypes: .wav audio/x-wav, content-types: .wav audio/wav
98
+ mimetypes: .obj application/octet-stream, content-types: .obj model/obj
99
+ mimetypes: .xml text/xml, content-types: .xml application/xml
100
+ mimetypes: .exe application/octet-stream, content-types: .exe application/x-msdownload
101
+ mimetypes: .dll application/octet-stream, content-types: .dll application/x-msdownload
102
+
103
+ There are 0 types in mimetypes that are not in content-types
104
+
105
+ There are 31 types in content-types that are not in mimetypes
106
+
107
+ .docx -> application/vnd.openxmlformats-officedocument.wordprocessingml.document
108
+ .m4v -> video/mp4
109
+ .odp -> application/vnd.oasis.opendocument.presentation
110
+ .deb -> application/x-debian-package
111
+ .glb -> model/gltf-binary
112
+ .php -> application/x-httpd-php
113
+ .xlsx -> application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
114
+ .woff -> font/woff
115
+ .tgz -> application/gzip
116
+ .ogg -> audio/ogg
117
+ .odt -> application/vnd.oasis.opendocument.text
118
+ .wmv -> video/x-ms-wmv
119
+ .stl -> model/stl
120
+ .ttf -> font/ttf
121
+ .flac -> audio/flac
122
+ .rar -> application/vnd.rar
123
+ .odg -> application/vnd.oasis.opendocument.graphics
124
+ .ods -> application/vnd.oasis.opendocument.spreadsheet
125
+ .weba -> audio/webm
126
+ .gltf -> model/gltf+json
127
+ .epub -> application/epub+zip
128
+ .m4a -> audio/mp4
129
+ .map -> application/json
130
+ .pptx -> application/vnd.openxmlformats-officedocument.presentationml.presentation
131
+ .woff2 -> font/woff2
132
+ .otf -> font/otf
133
+ .gz -> application/gzip
134
+ .rpm -> application/x-rpm
135
+ .7z -> application/x-7z-compressed
136
+ .ogv -> video/ogg
137
+ .apk -> application/vnd.android.package-archive
138
+ ```
139
+
140
+
141
+ ## Contributing
142
+
143
+ Contributions are welcome! Check out [the GitHub repo](https://github.com/mikeckennedy/content-types)
144
+ for more details on how to get involved.
@@ -0,0 +1,120 @@
1
+
2
+ # content-types 🗃️🔎
3
+
4
+ A Python library to map file extensions to MIME types.
5
+ It also provides a CLI for quick lookups right from your terminal.
6
+ If no known mapping is found, the tool returns `application/octet-stream`.
7
+
8
+ Unlike other libraries, this one does **not** try to access the file
9
+ or parse the bytes of the file or stream. It just looks at the extension
10
+ which is valuable when you don't have access to the file directly.
11
+ For example, you know the filename but it is stored in s3 and you don't want
12
+ to download it just to fully inspect the file.
13
+
14
+ Why not just use Python's built-in `mimetypes`? Or the excellent `python-magic` package? See below.
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ uv pip install content-types
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ```python
25
+ import content_types
26
+
27
+ # Forward lookup: filename -> MIME type
28
+ the_type = content_types.get_content_type("example.jpg")
29
+ print(the_type) # "image/jpeg"
30
+
31
+ # For very common files, you have shortcuts:
32
+ print(f'Content-Type for webp is {content_types.webp}.')
33
+ # Content-Type for webp is image/webp.
34
+ ```
35
+
36
+ ## CLI
37
+
38
+ To use the library as a CLI tool, just install it with **uv** or **pipx**.
39
+
40
+ ```bash
41
+ uv tool install content-types
42
+ ```
43
+
44
+ Now it will be available machine-wide.
45
+
46
+ ```bash
47
+ content-types example.jpg
48
+
49
+ # Outputs image/jpeg
50
+ ```
51
+
52
+ ## More correct than Python's `mimetypes`
53
+
54
+ When I first learned about Python's mimetypes module, I thought it was exactly what I need. However,
55
+ it doesn't have all the MIME types. And, it recommends deprecated, out-of-date answers for very obvious types.
56
+
57
+ For example, mimetypes has `.xml` as text/xml where it should be `application/xml`
58
+ (see [MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/MIME_types/Common_types)).
59
+
60
+ And mimetypes is missing important types such as:
61
+
62
+ - .m4v -> video/mp4
63
+ - .tgz -> application/gzip
64
+ - .flac -> audio/flac
65
+ - .epub -> application/epub+zip
66
+ - ...
67
+
68
+ Here is a full comparison found by running `samples/compare_to_builtin.py`:
69
+
70
+ ```text
71
+ There are 5 types where mimetypes and content-types disagree
72
+
73
+ mimetypes: .wav audio/x-wav, content-types: .wav audio/wav
74
+ mimetypes: .obj application/octet-stream, content-types: .obj model/obj
75
+ mimetypes: .xml text/xml, content-types: .xml application/xml
76
+ mimetypes: .exe application/octet-stream, content-types: .exe application/x-msdownload
77
+ mimetypes: .dll application/octet-stream, content-types: .dll application/x-msdownload
78
+
79
+ There are 0 types in mimetypes that are not in content-types
80
+
81
+ There are 31 types in content-types that are not in mimetypes
82
+
83
+ .docx -> application/vnd.openxmlformats-officedocument.wordprocessingml.document
84
+ .m4v -> video/mp4
85
+ .odp -> application/vnd.oasis.opendocument.presentation
86
+ .deb -> application/x-debian-package
87
+ .glb -> model/gltf-binary
88
+ .php -> application/x-httpd-php
89
+ .xlsx -> application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
90
+ .woff -> font/woff
91
+ .tgz -> application/gzip
92
+ .ogg -> audio/ogg
93
+ .odt -> application/vnd.oasis.opendocument.text
94
+ .wmv -> video/x-ms-wmv
95
+ .stl -> model/stl
96
+ .ttf -> font/ttf
97
+ .flac -> audio/flac
98
+ .rar -> application/vnd.rar
99
+ .odg -> application/vnd.oasis.opendocument.graphics
100
+ .ods -> application/vnd.oasis.opendocument.spreadsheet
101
+ .weba -> audio/webm
102
+ .gltf -> model/gltf+json
103
+ .epub -> application/epub+zip
104
+ .m4a -> audio/mp4
105
+ .map -> application/json
106
+ .pptx -> application/vnd.openxmlformats-officedocument.presentationml.presentation
107
+ .woff2 -> font/woff2
108
+ .otf -> font/otf
109
+ .gz -> application/gzip
110
+ .rpm -> application/x-rpm
111
+ .7z -> application/x-7z-compressed
112
+ .ogv -> video/ogg
113
+ .apk -> application/vnd.android.package-archive
114
+ ```
115
+
116
+
117
+ ## Contributing
118
+
119
+ Contributions are welcome! Check out [the GitHub repo](https://github.com/mikeckennedy/content-types)
120
+ for more details on how to get involved.
@@ -2,7 +2,7 @@ import sys
2
2
  from pathlib import Path
3
3
  from typing import Dict
4
4
 
5
- __VERSION__ = '0.2.2'
5
+ __VERSION__ = '0.2.3'
6
6
 
7
7
  # This dictionary maps file extensions (no dot) to the most specific content type.
8
8
 
@@ -16,9 +16,9 @@ EXTENSION_TO_CONTENT_TYPE: Dict[str, str] = {
16
16
  'csv': 'text/csv',
17
17
  'tsv': 'text/tab-separated-values',
18
18
  # JavaScript
19
- 'js': 'application/javascript', # commonly "application/javascript" nowadays
19
+ 'js': 'text/javascript',
20
20
  # MJS for ES modules
21
- 'mjs': 'application/javascript',
21
+ 'mjs': 'text/javascript',
22
22
  # JSON
23
23
  'json': 'application/json',
24
24
  'map': 'application/json',
@@ -33,7 +33,7 @@ EXTENSION_TO_CONTENT_TYPE: Dict[str, str] = {
33
33
  'webp': 'image/webp',
34
34
  'avif': 'image/avif',
35
35
  # Some new ones:
36
- 'ico': 'image/x-icon',
36
+ 'ico': 'image/vnd.microsoft.icon',
37
37
  'svg': 'image/svg+xml',
38
38
  'tif': 'image/tiff',
39
39
  'tiff': 'image/tiff',
@@ -58,6 +58,10 @@ EXTENSION_TO_CONTENT_TYPE: Dict[str, str] = {
58
58
  'flac': 'audio/flac',
59
59
  'm4a': 'audio/mp4',
60
60
  'weba': 'audio/webm',
61
+ 'ass': 'audio/aac',
62
+ 'adts': 'audio/aac',
63
+ 'rst': 'text/x-rst',
64
+ 'loas': 'audio/aac',
61
65
  # New ones:
62
66
  'mp2': 'audio/mpeg', # new
63
67
  'opus': 'audio/opus', # new
@@ -84,10 +88,10 @@ EXTENSION_TO_CONTENT_TYPE: Dict[str, str] = {
84
88
  'qt': 'video/quicktime',
85
89
  'movie': 'video/x-sgi-movie',
86
90
  # 3GP family (prefer official video/*):
87
- '3gp': 'video/3gpp',
88
- '3gpp': 'video/3gpp',
89
- '3g2': 'video/3gpp2',
90
- '3gpp2': 'video/3gpp2',
91
+ '3gp': 'audio/3gpp',
92
+ '3gpp': 'audio/3gpp',
93
+ '3g2': 'audio/3gpp2',
94
+ '3gpp2': 'audio/3gpp2',
91
95
  # Archives / Packages
92
96
  'pdf': 'application/pdf',
93
97
  'zip': 'application/zip',
@@ -216,6 +220,8 @@ EXTENSION_TO_CONTENT_TYPE: Dict[str, str] = {
216
220
  'sgm': 'text/x-sgml',
217
221
  'sgml': 'text/x-sgml',
218
222
  'vcf': 'text/x-vcard',
223
+ # Books
224
+ 'epub': 'application/epub+zip',
219
225
  }
220
226
 
221
227
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "content-types"
7
- version = "0.2.2" # You can manage version bumps manually or use a plugin for dynamic versioning
7
+ version = "0.2.3"
8
8
  description = "A library to map file extensions to content types and vice versa."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -0,0 +1,45 @@
1
+ import mimetypes
2
+
3
+ import content_types
4
+
5
+
6
+ def main():
7
+ print('Compare types in mimetypes vs content-types.')
8
+ in_mime_only = set()
9
+ differ = set()
10
+ for k, v in mimetypes.types_map.items():
11
+ cv_v = content_types.EXTENSION_TO_CONTENT_TYPE.get(k.lower().strip('.'))
12
+ if not cv_v:
13
+ in_mime_only.add((k, v))
14
+ continue
15
+
16
+ if cv_v != v:
17
+ differ.add(((k, v), (k, cv_v)))
18
+ continue
19
+
20
+ only_ct = set()
21
+ for k, v in content_types.EXTENSION_TO_CONTENT_TYPE.items():
22
+ mv = mimetypes.types_map.get('.' + k)
23
+ if not mv:
24
+ only_ct.add((k, v))
25
+ continue
26
+
27
+ print(f'There are {len(differ):,} types where mimetypes and content-types disagree')
28
+ for (mk, mv), (ct_k, ct_v) in differ:
29
+ print(f'mimetypes: {mk} {mv}, content-types: {ct_k} {ct_v}')
30
+ print()
31
+
32
+ print(f'There are {len(in_mime_only):,} types in mimetypes that are not in content-types')
33
+ for k, v in in_mime_only:
34
+ print(f'{k.ljust(6)}: {v}')
35
+ print()
36
+
37
+ print(f'There are {len(only_ct):,} types in content-types that are not in mimetypes')
38
+ print('in_ct_only')
39
+ for k, v in only_ct:
40
+ print(f'.{k.ljust(4)} -> {v}')
41
+ print()
42
+
43
+
44
+ if __name__ == '__main__':
45
+ main()
@@ -1,77 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: content-types
3
- Version: 0.2.2
4
- Summary: A library to map file extensions to content types and vice versa.
5
- Project-URL: Homepage, https://github.com/mikeckennedy/content-types
6
- Project-URL: Bug Reports, https://github.com/mikeckennedy/content-types/issues
7
- Project-URL: Source, https://github.com/mikeckennedy/content-types
8
- Author-email: Michael Kennedy <mikeckennedy@gmail.com>
9
- License-Expression: MIT
10
- License-File: LICENSE
11
- Keywords: content-type,file extensions,mapping,mime
12
- Classifier: Intended Audience :: Developers
13
- Classifier: License :: OSI Approved :: MIT License
14
- Classifier: Operating System :: OS Independent
15
- Classifier: Programming Language :: Python :: 3.10
16
- Classifier: Programming Language :: Python :: 3.11
17
- Classifier: Programming Language :: Python :: 3.12
18
- Classifier: Programming Language :: Python :: 3.13
19
- Classifier: Programming Language :: Python :: 3.14
20
- Classifier: Topic :: Internet :: WWW/HTTP
21
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
- Requires-Python: <=3.14,>=3.10
23
- Description-Content-Type: text/markdown
24
-
25
-
26
- # content-types 🗃️🔎
27
-
28
- A Python library to map file extensions to MIME types.
29
- It also provides a CLI for quick lookups right from your terminal.
30
- If no known mapping is found, the tool returns `application/octet-stream`.
31
-
32
- Unlike other libraries, this one does **not** try to access the file
33
- or parse the bytes of the file or stream. It just looks at the extension
34
- which is valuable when you don't have access to the file directly.
35
- For example, you know the filename but it is stored in s3 and you don't want
36
- to download it just to fully inspect the file.
37
-
38
- ## Installation
39
-
40
- ```bash
41
- uv pip install content-types
42
- ```
43
-
44
- ## Usage
45
-
46
- ```python
47
- import content_types
48
-
49
- # Forward lookup: filename -> MIME type
50
- the_type = content_types.get_content_type("example.jpg")
51
- print(the_type) # "image/jpeg"
52
-
53
- # For very common files, you have shortcuts:
54
- print(f'Content-Type for webp is {content_types.webp}.')
55
- # Content-Type for webp is image/webp.
56
- ```
57
-
58
- ## CLI
59
-
60
- To use the library as a CLI tool, just install it with **uv** or **pipx**.
61
-
62
- ```bash
63
- uv tool install content-types
64
- ```
65
-
66
- Now it will be available machine-wide.
67
-
68
- ```bash
69
- content-types example.jpg
70
-
71
- # Outputs image/jpeg
72
- ```
73
-
74
- ## Contributing
75
-
76
- Contributions are welcome! Check out [the GitHub repo](https://github.com/mikeckennedy/content-types)
77
- for more details on how to get involved.
@@ -1,53 +0,0 @@
1
-
2
- # content-types 🗃️🔎
3
-
4
- A Python library to map file extensions to MIME types.
5
- It also provides a CLI for quick lookups right from your terminal.
6
- If no known mapping is found, the tool returns `application/octet-stream`.
7
-
8
- Unlike other libraries, this one does **not** try to access the file
9
- or parse the bytes of the file or stream. It just looks at the extension
10
- which is valuable when you don't have access to the file directly.
11
- For example, you know the filename but it is stored in s3 and you don't want
12
- to download it just to fully inspect the file.
13
-
14
- ## Installation
15
-
16
- ```bash
17
- uv pip install content-types
18
- ```
19
-
20
- ## Usage
21
-
22
- ```python
23
- import content_types
24
-
25
- # Forward lookup: filename -> MIME type
26
- the_type = content_types.get_content_type("example.jpg")
27
- print(the_type) # "image/jpeg"
28
-
29
- # For very common files, you have shortcuts:
30
- print(f'Content-Type for webp is {content_types.webp}.')
31
- # Content-Type for webp is image/webp.
32
- ```
33
-
34
- ## CLI
35
-
36
- To use the library as a CLI tool, just install it with **uv** or **pipx**.
37
-
38
- ```bash
39
- uv tool install content-types
40
- ```
41
-
42
- Now it will be available machine-wide.
43
-
44
- ```bash
45
- content-types example.jpg
46
-
47
- # Outputs image/jpeg
48
- ```
49
-
50
- ## Contributing
51
-
52
- Contributions are welcome! Check out [the GitHub repo](https://github.com/mikeckennedy/content-types)
53
- for more details on how to get involved.
File without changes
File without changes
File without changes