Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 22, 23:15 UTC
feat: add file upload/download utilities (#1669)
Viraj committed
Jun 19, 2025 at 19:00 UTC
8a4b5bc28a4f1eec4ef3f1700ae16de35867c2af
3 files changed
+854
-1
python/composio/core/models/_files.py
new
+329
@@ -0,0 +1,329 @@
1
+from __future__ import annotations
2
+
3
+import hashlib
4
+import json
5
+import os
6
+import typing as t
7
+from pathlib import Path
8
+
9
+import requests
10
+import typing_extensions as te
11
+from composio_client import BaseModel as _ComposioBaseModel
12
+from pydantic import BaseModel, ConfigDict, Field
13
+
14
+from composio.client import HttpClient
15
+from composio.client.types import Tool
16
+from composio.exceptions import (
17
+ ErrorDownloadingFile,
18
+ ErrorUploadingFile,
19
+ SDKFileNotFoundError,
20
+)
21
+from composio.utils import mimetypes
22
+from composio.utils.logging import WithLogger
23
+
24
+if t.TYPE_CHECKING:
25
+ from .tools import ToolExecutionResponse
26
+
27
+_DEFAULT_CHUNK_SIZE = 1024 * 1024
28
+_FILE_UPLOAD = "/api/v3/files/upload/request"
29
+
30
+LOCAL_CACHE_DIRECTORY_NAME = ".composio"
31
+"""
32
+Local cache directory name for composio CLI
33
+"""
34
+
35
+ENV_LOCAL_CACHE_DIRECTORY = "COMPOSIO_CACHE_DIR"
36
+"""
37
+Environment to set the composio caching directory.
38
+"""
39
+
40
+LOCAL_CACHE_DIRECTORY = Path(
41
+ os.environ.get(
42
+ ENV_LOCAL_CACHE_DIRECTORY,
43
+ Path.home() / LOCAL_CACHE_DIRECTORY_NAME, # Fallback to user directory
44
+ )
45
+)
46
+"""
47
+Path to local caching directory.
48
+"""
49
+
50
+try:
51
+ LOCAL_CACHE_DIRECTORY.mkdir(parents=True, exist_ok=True)
52
+ if not os.access(LOCAL_CACHE_DIRECTORY, os.W_OK):
53
+ raise OSError
54
+except OSError as e:
55
+ raise RuntimeError(
56
+ f"Cache directory {LOCAL_CACHE_DIRECTORY} is not writable please "
57
+ f"provide a path that is writable using {ENV_LOCAL_CACHE_DIRECTORY} "
58
+ "environment variable."
59
+ ) from e
60
+
61
+
62
+LOCAL_OUTPUT_FILE_DIRECTORY = LOCAL_CACHE_DIRECTORY / "outputs"
63
+"""
64
+Local output file directory name for composio tools
65
+"""
66
+
67
+
68
+def get_md5(file: Path):
69
+ obj = hashlib.md5()
70
+ with file.open("rb") as fp:
71
+ while True:
72
+ line = fp.read(_DEFAULT_CHUNK_SIZE)
73
+ if not line:
74
+ break
75
+ obj.update(line)
76
+ return obj.hexdigest()
77
+
78
+
79
+def upload(url: str, file: Path) -> bool:
80
+ with file.open("rb") as data:
81
+ return requests.put(url=url, data=data).status_code in (200, 403)
82
+
83
+
84
+class _FileUploadResponse(_ComposioBaseModel):
85
+ id: str
86
+ key: str
87
+ type: str
88
+ new_presigned_url: str
89
+
90
+
91
+class FileUploadable(BaseModel):
92
+ model_config = ConfigDict(json_schema_extra={"file_uploadable": True})
93
+
94
+ name: str
95
+ mimetype: str
96
+ s3key: str
97
+
98
+ @classmethod
99
+ def from_path(
100
+ cls,
101
+ client: HttpClient,
102
+ file: t.Union[str, Path],
103
+ tool: str,
104
+ toolkit: str,
105
+ ) -> te.Self:
106
+ file = Path(file)
107
+ if not file.exists():
108
+ raise SDKFileNotFoundError(
109
+ f"File not found: {file}. Please provide a valid file path."
110
+ )
111
+
112
+ if not file.is_file():
113
+ raise SDKFileNotFoundError(
114
+ f"Not a file: {file}. Please provide a valid file path."
115
+ )
116
+
117
+ if not os.access(file, os.R_OK):
118
+ raise SDKFileNotFoundError(
119
+ f"File not readable: {file}. Please check the file permissions."
120
+ )
121
+
122
+ mimetype = mimetypes.guess(file=file)
123
+ s3meta = client.post(
124
+ path=_FILE_UPLOAD,
125
+ body={
126
+ "md5": get_md5(file=file),
127
+ "filename": file.name,
128
+ "mimetype": mimetype,
129
+ "tool_slug": tool,
130
+ "toolkit_slug": toolkit,
131
+ },
132
+ cast_to=_FileUploadResponse,
133
+ )
134
+ if not upload(url=s3meta.new_presigned_url, file=file):
135
+ raise ErrorUploadingFile(f"Error uploading file: {file}")
136
+ return cls(name=file.name, mimetype=mimetype, s3key=s3meta.key)
137
+
138
+
139
+class FileDownloadable(BaseModel):
140
+ model_config = ConfigDict(json_schema_extra={"file_downloadable": True})
141
+
142
+ name: str = Field(..., description="Name of the file")
143
+ mimetype: str = Field(..., description="Mime type of the file.")
144
+ s3url: str = Field(..., description="URL of the file.")
145
+
146
+ def download(self, outdir: Path, chunk_size: int = _DEFAULT_CHUNK_SIZE) -> Path:
147
+ outfile = outdir / self.name
148
+ outdir.mkdir(exist_ok=True, parents=True)
149
+ response = requests.get(url=self.s3url, stream=True)
150
+ if response.status_code != 200:
151
+ raise ErrorDownloadingFile(f"Error downloading file: {self.s3url}")
152
+
153
+ with outfile.open("wb") as fd:
154
+ for chunk in response.iter_content(chunk_size=chunk_size):
155
+ fd.write(chunk)
156
+ return outfile
157
+
158
+
159
+class FileHelper(WithLogger):
160
+ def __init__(self, client: HttpClient):
161
+ super().__init__()
162
+ self._client = client
163
+
164
+ def _file_uploadable(self, schema: t.Dict):
165
+ if "allOf" in schema:
166
+ return any(
167
+ (
168
+ _schema.get("file_uploadable", False)
169
+ if isinstance(_schema, dict)
170
+ else False
171
+ )
172
+ for _schema in schema["allOf"]
173
+ )
174
+ return schema.get("file_uploadable", False)
175
+
176
+ def _process_file_uploadable(self, schema: t.Dict):
177
+ return {
178
+ "type": "string",
179
+ "format": "path",
180
+ "description": schema.get("description", "Path to file."),
181
+ "title": schema.get("title"),
182
+ }
183
+
184
+ def process_schema_recursively(self, schema: t.Dict) -> t.Dict:
185
+ required = schema.get("required") or []
186
+ for _param, _schema in schema["properties"].items():
187
+ if self._file_uploadable(schema=_schema):
188
+ schema["properties"][_param] = self._process_file_uploadable(
189
+ schema=_schema
190
+ )
191
+
192
+ if _schema.get("type") in ["string", "integer", "number", "boolean"]:
193
+ ext = f"Please provide a value of type {_schema['type']}."
194
+ description = _schema.get("description", "").rstrip(".")
195
+ _schema["description"] = f"{description}. {ext}" if description else ext
196
+
197
+ if _param in required:
198
+ description = _schema.get("description")
199
+ _schema["description"] = (
200
+ (f"{description.rstrip('.')}. This parameter is required.")
201
+ if description
202
+ else "This parameter is required."
203
+ )
204
+ return schema
205
+
206
+ def _substitute_file_uploads_recursively(
207
+ self,
208
+ tool: Tool,
209
+ schema: t.Dict,
210
+ request: t.Dict,
211
+ ) -> t.Dict:
212
+ if "properties" not in schema:
213
+ return request
214
+
215
+ params = schema["properties"]
216
+ for _param in list(request.keys()):
217
+ if _param not in params:
218
+ continue
219
+
220
+ if self._file_uploadable(schema=params[_param]):
221
+ # skip if the file is not provided
222
+ if request[_param] is None or request[_param] == "":
223
+ del request[_param]
224
+ continue
225
+
226
+ request[_param] = FileUploadable.from_path(
227
+ client=self._client,
228
+ file=request[_param],
229
+ tool=tool.slug,
230
+ toolkit=tool.toolkit.slug,
231
+ ).model_dump()
232
+ continue
233
+
234
+ if isinstance(request[_param], dict) and params[_param]["type"] == "object":
235
+ request[_param] = self._substitute_file_uploads_recursively(
236
+ schema=params[_param],
237
+ request=request[_param],
238
+ tool=tool,
239
+ )
240
+ continue
241
+
242
+ return request
243
+
244
+ def substitute_file_uploads(self, tool: Tool, request: t.Dict) -> t.Dict:
245
+ return self._substitute_file_uploads_recursively(
246
+ tool=tool,
247
+ schema=tool.input_parameters,
248
+ request=request,
249
+ )
250
+
251
+ def _is_file_downloadable(self, schema: t.Dict) -> bool:
252
+ if "allOf" in schema:
253
+ return any(
254
+ (
255
+ _schema.get("file_downloadable", False)
256
+ if isinstance(_schema, dict)
257
+ else False
258
+ )
259
+ for _schema in schema["allOf"]
260
+ )
261
+ return schema.get("file_downloadable", False)
262
+
263
+ def _find_file_downloadable_from_any_of(
264
+ self, schemas: list[dict]
265
+ ) -> t.Optional[t.Dict]:
266
+ for schema in schemas:
267
+ if "type" not in schema or schema["type"] != "object":
268
+ continue
269
+
270
+ if self._is_file_downloadable(schema=schema):
271
+ return schema
272
+
273
+ # Hack to avoid recursive check, maybe use recursion
274
+ if '"file_downloadable":true' in json.dumps(schema):
275
+ return schema
276
+
277
+ return None
278
+
279
+ def _substitute_file_downloads_recursively(
280
+ self,
281
+ tool: Tool,
282
+ schema: t.Dict,
283
+ request: t.Dict,
284
+ ) -> t.Dict:
285
+ if "properties" not in schema:
286
+ return request
287
+
288
+ params = schema["properties"]
289
+ for _param in request:
290
+ if _param not in params:
291
+ continue
292
+
293
+ if self._is_file_downloadable(schema=params[_param]):
294
+ request[_param] = str(
295
+ FileDownloadable(**request[_param]).download(
296
+ LOCAL_OUTPUT_FILE_DIRECTORY / tool.toolkit.slug / tool.slug
297
+ )
298
+ )
299
+ continue
300
+
301
+ if "anyOf" in params[_param]:
302
+ obj = self._find_file_downloadable_from_any_of(params[_param]["anyOf"])
303
+ if obj is None:
304
+ continue
305
+ params[_param] = obj
306
+
307
+ if isinstance(request[_param], dict) and params[_param]["type"] == "object":
308
+ request[_param] = self._substitute_file_downloads_recursively(
309
+ schema=params[_param],
310
+ request=request[_param],
311
+ tool=tool,
312
+ )
313
+ continue
314
+
315
+ return request
316
+
317
+ def substitute_file_downloads(
318
+ self,
319
+ tool: Tool,
320
+ response: ToolExecutionResponse,
321
+ ) -> ToolExecutionResponse:
322
+ return t.cast(
323
+ "ToolExecutionResponse",
324
+ self._substitute_file_downloads_recursively(
325
+ tool=tool,
326
+ schema=tool.output_parameters,
327
+ request=t.cast(dict, response),
328
+ ),
329
+ )
python/composio/core/models/tools.py
+15
-1
@@ -12,6 +12,7 @@ from composio.client.types import (
12
tool_proxy_params,
13
tool_proxy_response,
14
)
15
+from composio.core.models._files import FileHelper
16
from composio.core.models.base import Resource
17
from composio.core.models.custom_tools import CustomTools
18
from composio.core.provider import (
@@ -60,6 +61,7 @@ class Tools(Resource, t.Generic[TProvider]):
61
self._client = client
62
self._custom_tools = CustomTools(client)
63
self._tool_schemas: t.Dict[str, Tool] = {}
64
+ self._file_helper = FileHelper(client=self._client)
65
66
self.custom_tool = self._custom_tools.register
67
self.provider = provider
@@ -145,6 +147,11 @@ class Tools(Resource, t.Generic[TProvider]):
147
]
148
149
self._tool_schemas.update({tool.slug: tool for tool in tools_list})
150
+ for tool in tools_list:
151
+ tool.input_parameters = self._file_helper.process_schema_recursively(
152
+ schema=tool.input_parameters,
153
+ )
154
+
155
if issubclass(type(self.provider), NonAgenticProvider):
156
t.cast(NonAgenticProvider, self.provider).set_execute_tool_fn(
157
t.cast(
@@ -356,6 +363,10 @@ class Tools(Resource, t.Generic[TProvider]):
363
user_id = processed_params["user_id"]
364
arguments = processed_params["arguments"]
365
366
+ arguments = self._file_helper.substitute_file_uploads(
367
+ tool=tool,
368
+ request=arguments,
369
+ )
370
response = (
371
self._execute_custom_tool(slug=slug, arguments=arguments)
372
if self._custom_tools.get(slug) is not None
@@ -369,7 +380,10 @@ class Tools(Resource, t.Generic[TProvider]):
380
version=version,
381
)
382
)
372
-
383
+ response = self._file_helper.substitute_file_downloads(
384
+ tool=tool,
385
+ response=response,
386
+ )
387
if modifiers is not None:
388
response = apply_modifier_by_type(
389
modifiers=modifiers,
python/composio/utils/mimetypes.py
new
+510
@@ -0,0 +1,510 @@
1
+import typing as t
2
+from pathlib import Path
3
+
4
+_default = "application/octet-stream"
5
+_types = {
6
+ ".3dm": "x-world/x-3dmf",
7
+ ".3dmf": "x-world/x-3dmf",
8
+ ".7z": "application/x-7z-compressed",
9
+ ".a": "application/octet-stream",
10
+ ".aab": "application/x-authorware-bin",
11
+ ".aam": "application/x-authorware-map",
12
+ ".aas": "application/x-authorware-seg",
13
+ ".abc": "text/vnd.abc",
14
+ ".acgi": "text/html",
15
+ ".afl": "video/animaflex",
16
+ ".ai": "application/postscript",
17
+ ".aif": "audio/x-aiff",
18
+ ".aifc": "audio/x-aiff",
19
+ ".aiff": "audio/x-aiff",
20
+ ".aim": "application/x-aim",
21
+ ".aip": "text/x-audiosoft-intra",
22
+ ".ani": "application/x-navi-animation",
23
+ ".aos": "application/x-nokia-9000-communicator-add-on-software",
24
+ ".aps": "application/mime",
25
+ ".arc": "application/octet-stream",
26
+ ".arj": "application/octet-stream",
27
+ ".art": "image/x-jg",
28
+ ".asf": "video/x-ms-asf",
29
+ ".asm": "text/x-asm",
30
+ ".asp": "text/asp",
31
+ ".asx": "video/x-ms-asf-plugin",
32
+ ".au": "audio/basic",
33
+ ".avi": "video/x-msvideo",
34
+ ".avs": "video/avs-video",
35
+ ".bcpio": "application/x-bcpio",
36
+ ".bin": "application/octet-stream",
37
+ ".bm": "image/bmp",
38
+ ".bmp": "image/x-ms-bmp",
39
+ ".boo": "application/book",
40
+ ".book": "application/book",
41
+ ".boz": "application/x-bzip2",
42
+ ".bsh": "application/x-bsh",
43
+ ".bz": "application/x-bzip",
44
+ ".bz2": "application/x-bzip2",
45
+ ".c": "text/plain",
46
+ ".c+": "text/plain",
47
+ ".cat": "application/vnd.ms-pki.seccat",
48
+ ".cc": "text/x-c",
49
+ ".ccad": "application/clariscad",
50
+ ".cco": "application/x-cocoa",
51
+ ".cdf": "application/x-netcdf",
52
+ ".cer": "application/x-x509-ca-cert",
53
+ ".cha": "application/x-chat",
54
+ ".chat": "application/x-chat",
55
+ ".class": "application/x-java-class",
56
+ ".com": "text/plain",
57
+ ".conf": "text/plain",
58
+ ".cpio": "application/x-cpio",
59
+ ".cpp": "text/x-c",
60
+ ".cpt": "application/x-cpt",
61
+ ".crl": "application/pkix-crl",
62
+ ".crt": "application/x-x509-user-cert",
63
+ ".csh": "application/x-csh",
64
+ ".css": "text/css",
65
+ ".csv": "text/csv",
66
+ ".cxx": "text/plain",
67
+ ".dcr": "application/x-director",
68
+ ".deepv": "application/x-deepv",
69
+ ".def": "text/plain",
70
+ ".der": "application/x-x509-ca-cert",
71
+ ".dif": "video/x-dv",
72
+ ".dir": "application/x-director",
73
+ ".dl": "video/x-dl",
74
+ ".doc": "application/msword",
75
+ ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
76
+ ".dot": "application/msword",
77
+ ".dp": "application/commonground",
78
+ ".drw": "application/drafting",
79
+ ".dump": "application/octet-stream",
80
+ ".dv": "video/x-dv",
81
+ ".dvi": "application/x-dvi",
82
+ ".dwf": "model/vnd.dwf",
83
+ ".dwg": "image/x-dwg",
84
+ ".dxf": "image/x-dwg",
85
+ ".dxr": "application/x-director",
86
+ ".el": "text/x-script.elisp",
87
+ ".elc": "application/x-elc",
88
+ ".env": "application/x-envoy",
89
+ ".eot": "application/vnd.ms-fontobject",
90
+ ".eps": "application/postscript",
91
+ ".es": "application/x-esrehber",
92
+ ".etx": "text/x-setext",
93
+ ".evy": "application/x-envoy",
94
+ ".exe": "application/octet-stream",
95
+ ".f": "text/x-fortran",
96
+ ".f77": "text/x-fortran",
97
+ ".f90": "text/x-fortran",
98
+ ".fdf": "application/vnd.fdf",
99
+ ".fif": "image/fif",
100
+ ".flac": "audio/flac",
101
+ ".fli": "video/x-fli",
102
+ ".flo": "image/florian",
103
+ ".flx": "text/vnd.fmi.flexstor",
104
+ ".fmf": "video/x-atomic3d-feature",
105
+ ".for": "text/x-fortran",
106
+ ".fpx": "image/vnd.net-fpx",
107
+ ".frl": "application/freeloader",
108
+ ".funk": "audio/make",
109
+ ".g": "text/plain",
110
+ ".g3": "image/g3fax",
111
+ ".gif": "image/gif",
112
+ ".gl": "video/x-gl",
113
+ ".gsd": "audio/x-gsm",
114
+ ".gsm": "audio/x-gsm",
115
+ ".gsp": "application/x-gsp",
116
+ ".gss": "application/x-gss",
117
+ ".gtar": "application/x-gtar",
118
+ ".gz": "application/x-gzip",
119
+ ".gzip": "multipart/x-gzip",
120
+ ".h": "text/plain",
121
+ ".hdf": "application/x-hdf",
122
+ ".help": "application/x-helpfile",
123
+ ".hgl": "application/vnd.hp-hpgl",
124
+ ".hh": "text/x-h",
125
+ ".hlb": "text/x-script",
126
+ ".hlp": "application/x-winhelp",
127
+ ".hpg": "application/vnd.hp-hpgl",
128
+ ".hpgl": "application/vnd.hp-hpgl",
129
+ ".hqx": "application/x-mac-binhex40",
130
+ ".hta": "application/hta",
131
+ ".htc": "text/x-component",
132
+ ".htm": "text/html",
133
+ ".html": "text/html",
134
+ ".htmls": "text/html",
135
+ ".htt": "text/webviewhtml",
136
+ ".htx": "text/html",
137
+ ".ice": "x-conference/x-cooltalk",
138
+ ".ico": "image/vnd.microsoft.icon",
139
+ ".ics": "text/calendar",
140
+ ".idc": "text/plain",
141
+ ".ief": "image/ief",
142
+ ".iefs": "image/ief",
143
+ ".iges": "model/iges",
144
+ ".igs": "model/iges",
145
+ ".ima": "application/x-ima",
146
+ ".imap": "application/x-httpd-imap",
147
+ ".inf": "application/inf",
148
+ ".ins": "application/x-internett-signup",
149
+ ".ip": "application/x-ip2",
150
+ ".isu": "video/x-isvideo",
151
+ ".it": "audio/it",
152
+ ".iv": "application/x-inventor",
153
+ ".ivr": "i-world/i-vrml",
154
+ ".ivy": "application/x-livescreen",
155
+ ".jam": "audio/x-jam",
156
+ ".jav": "text/x-java-source",
157
+ ".java": "text/x-java-source",
158
+ ".jcm": "application/x-java-commerce",
159
+ ".jfif": "image/pjpeg",
160
+ ".jfif-bnl": "image/jpeg",
161
+ ".jpe": "image/jpeg",
162
+ ".jpeg": "image/jpeg",
163
+ ".jpg": "image/jpg",
164
+ ".jps": "image/x-jps",
165
+ ".js": "application/javascript",
166
+ ".json": "application/json",
167
+ ".jut": "image/jutvision",
168
+ ".kar": "music/x-karaoke",
169
+ ".ksh": "text/plain",
170
+ ".la": "audio/x-nspaudio",
171
+ ".lam": "audio/x-liveaudio",
172
+ ".latex": "application/x-latex",
173
+ ".lha": "application/x-lha",
174
+ ".lhx": "application/octet-stream",
175
+ ".list": "text/plain",
176
+ ".lma": "audio/x-nspaudio",
177
+ ".log": "text/plain",
178
+ ".lsp": "text/x-script.lisp",
179
+ ".lst": "text/plain",
180
+ ".lsx": "text/x-la-asf",
181
+ ".ltx": "application/x-latex",
182
+ ".lzh": "application/x-lzh",
183
+ ".lzx": "application/x-lzx",
184
+ ".m": "text/x-m",
185
+ ".m1v": "video/mpeg",
186
+ ".m2a": "audio/mpeg",
187
+ ".m2v": "video/mpeg",
188
+ ".m3u": "application/vnd.apple.mpegurl",
189
+ ".man": "application/x-troff-man",
190
+ ".map": "application/x-navimap",
191
+ ".mar": "text/plain",
192
+ ".mbd": "application/mbedlet",
193
+ ".mc": "application/x-magic-cap-package-1.0",
194
+ ".mcd": "application/x-mathcad",
195
+ ".mcf": "text/mcf",
196
+ ".mcp": "application/netmc",
197
+ ".me": "application/x-troff-me",
198
+ ".mht": "message/rfc822",
199
+ ".mhtml": "message/rfc822",
200
+ ".mid": "audio/midi",
201
+ ".midi": "audio/midi",
202
+ ".mif": "application/x-mif",
203
+ ".mime": "www/mime",
204
+ ".mjf": "audio/x-vnd.audioexplosion.mjuicemediafile",
205
+ ".mjpg": "video/x-motion-jpeg",
206
+ ".mka": "audio/x-matroska",
207
+ ".mkv": "video/x-matroska",
208
+ ".mm": "application/x-meme",
209
+ ".mme": "application/base64",
210
+ ".mod": "audio/x-mod",
211
+ ".moov": "video/quicktime",
212
+ ".mov": "video/quicktime",
213
+ ".movie": "video/x-sgi-movie",
214
+ ".mp2": "audio/mpeg",
215
+ ".mp3": "audio/mpeg",
216
+ ".mp4": "video/mp4",
217
+ ".mpa": "video/mpeg",
218
+ ".mpc": "application/x-project",
219
+ ".mpe": "video/mpeg",
220
+ ".mpeg": "video/mpeg",
221
+ ".mpg": "video/mpeg",
222
+ ".mpga": "audio/mpeg",
223
+ ".mpp": "application/vnd.ms-project",
224
+ ".mpt": "application/x-project",
225
+ ".mpv": "application/x-project",
226
+ ".mpx": "application/x-project",
227
+ ".mrc": "application/marc",
228
+ ".ms": "application/x-troff-ms",
229
+ ".mv": "video/x-sgi-movie",
230
+ ".my": "audio/make",
231
+ ".mzz": "application/x-vnd.audioexplosion.mzz",
232
+ ".nap": "image/naplps",
233
+ ".naplps": "image/naplps",
234
+ ".nc": "application/x-netcdf",
235
+ ".ncm": "application/vnd.nokia.configuration-message",
236
+ ".nif": "image/x-niff",
237
+ ".niff": "image/x-niff",
238
+ ".nix": "application/x-mix-transfer",
239
+ ".nsc": "application/x-conference",
240
+ ".nvd": "application/x-navidoc",
241
+ ".o": "application/octet-stream",
242
+ ".oda": "application/oda",
243
+ ".ogg": "video/ogg",
244
+ ".omc": "application/x-omc",
245
+ ".omcd": "application/x-omcdatamaker",
246
+ ".omcr": "application/x-omcregerator",
247
+ ".otf": "font/otf",
248
+ ".p": "text/x-pascal",
249
+ ".p10": "application/x-pkcs10",
250
+ ".p12": "application/x-pkcs12",
251
+ ".p7a": "application/x-pkcs7-signature",
252
+ ".p7c": "application/pkcs7-mime",
253
+ ".p7m": "application/x-pkcs7-mime",
254
+ ".p7r": "application/x-pkcs7-certreqresp",
255
+ ".p7s": "application/pkcs7-signature",
256
+ ".part": "application/pro_eng",
257
+ ".pas": "text/pascal",
258
+ ".pbm": "image/x-portable-bitmap",
259
+ ".pcl": "application/x-pcl",
260
+ ".pct": "image/pict",
261
+ ".pcx": "image/x-pcx",
262
+ ".pdb": "chemical/x-pdb",
263
+ ".pdf": "application/pdf",
264
+ ".pfunk": "audio/make.my.funk",
265
+ ".pgm": "image/x-portable-graymap",
266
+ ".pic": "image/pict",
267
+ ".pict": "image/pict",
268
+ ".pkg": "application/x-newton-compatible-pkg",
269
+ ".pko": "application/vnd.ms-pki.pko",
270
+ ".pl": "text/plain",
271
+ ".plx": "application/x-pixclscript",
272
+ ".pm": "text/x-script.perl-module",
273
+ ".pm4": "application/x-pagemaker",
274
+ ".pm5": "application/x-pagemaker",
275
+ ".png": "image/png",
276
+ ".pnm": "image/x-portable-anymap",
277
+ ".pot": "application/vnd.ms-powerpoint",
278
+ ".pov": "model/x-pov",
279
+ ".ppa": "application/vnd.ms-powerpoint",
280
+ ".ppm": "image/x-portable-pixmap",
281
+ ".pps": "application/vnd.ms-powerpoint",
282
+ ".ppt": "application/vnd.ms-powerpoint",
283
+ ".pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
284
+ ".ppz": "application/mspowerpoint",
285
+ ".pre": "application/x-freelance",
286
+ ".prt": "application/pro_eng",
287
+ ".ps": "application/postscript",
288
+ ".psd": "application/octet-stream",
289
+ ".pvu": "paleovu/x-pv",
290
+ ".pwz": "application/vnd.ms-powerpoint",
291
+ ".py": "text/x-python",
292
+ ".pyc": "application/x-python-code",
293
+ ".qcp": "audio/vnd.qcelp",
294
+ ".qd3": "x-world/x-3dmf",
295
+ ".qd3d": "x-world/x-3dmf",
296
+ ".qif": "image/x-quicktime",
297
+ ".qt": "video/quicktime",
298
+ ".qtc": "video/x-qtc",
299
+ ".qti": "image/x-quicktime",
300
+ ".qtif": "image/x-quicktime",
301
+ ".ra": "audio/x-pn-realaudio",
302
+ ".ram": "application/x-pn-realaudio",
303
+ ".ras": "image/x-cmu-raster",
304
+ ".rast": "image/cmu-raster",
305
+ ".rar": "application/vnd.rar",
306
+ ".rexx": "text/x-script.rexx",
307
+ ".rf": "image/vnd.rn-realflash",
308
+ ".rgb": "image/x-rgb",
309
+ ".rm": "audio/x-pn-realaudio",
310
+ ".rmi": "audio/mid",
311
+ ".rmm": "audio/x-pn-realaudio",
312
+ ".rmp": "audio/x-pn-realaudio-plugin",
313
+ ".rng": "application/vnd.nokia.ringing-tone",
314
+ ".rnx": "application/vnd.rn-realplayer",
315
+ ".roff": "application/x-troff",
316
+ ".rp": "image/vnd.rn-realpix",
317
+ ".rpm": "audio/x-pn-realaudio-plugin",
318
+ ".rt": "text/vnd.rn-realtext",
319
+ ".rtf": "application/rtf",
320
+ ".rtx": "text/richtext",
321
+ ".rv": "video/vnd.rn-realvideo",
322
+ ".s": "text/x-asm",
323
+ ".s3m": "audio/s3m",
324
+ ".saveme": "application/octet-stream",
325
+ ".sbk": "application/x-tbook",
326
+ ".scm": "video/x-scm",
327
+ ".sdml": "text/plain",
328
+ ".sdp": "application/x-sdp",
329
+ ".sdr": "application/sounder",
330
+ ".sea": "application/x-sea",
331
+ ".set": "application/set",
332
+ ".sgm": "text/x-sgml",
333
+ ".sgml": "text/x-sgml",
334
+ ".sh": "application/x-sh",
335
+ ".shar": "application/x-shar",
336
+ ".shtml": "text/x-server-parsed-html",
337
+ ".sid": "audio/x-psid",
338
+ ".sit": "application/x-stuffit",
339
+ ".skd": "application/x-koan",
340
+ ".skm": "application/x-koan",
341
+ ".skp": "application/x-koan",
342
+ ".skt": "application/x-koan",
343
+ ".sl": "application/x-seelogo",
344
+ ".smi": "application/smil",
345
+ ".smil": "application/smil",
346
+ ".snd": "audio/basic",
347
+ ".sol": "application/solids",
348
+ ".spc": "text/x-speech",
349
+ ".spl": "application/futuresplash",
350
+ ".spr": "application/x-sprite",
351
+ ".sprite": "application/x-sprite",
352
+ ".src": "application/x-wais-source",
353
+ ".ssi": "text/x-server-parsed-html",
354
+ ".ssm": "application/streamingmedia",
355
+ ".sst": "application/vnd.ms-pki.certstore",
356
+ ".step": "application/step",
357
+ ".stl": "application/x-navistyle",
358
+ ".stp": "application/step",
359
+ ".sv4cpio": "application/x-sv4cpio",
360
+ ".sv4crc": "application/x-sv4crc",
361
+ ".svf": "image/x-dwg",
362
+ ".svg": "image/svg+xml",
363
+ ".svr": "x-world/x-svr",
364
+ ".swf": "application/x-shockwave-flash",
365
+ ".t": "application/x-troff",
366
+ ".talk": "text/x-speech",
367
+ ".tar": "application/x-tar",
368
+ ".tbk": "application/x-tbook",
369
+ ".tcl": "application/x-tcl",
370
+ ".tcsh": "text/x-script.tcsh",
371
+ ".tex": "application/x-tex",
372
+ ".texi": "application/x-texinfo",
373
+ ".texinfo": "application/x-texinfo",
374
+ ".text": "text/plain",
375
+ ".tgz": "application/x-compressed",
376
+ ".tif": "image/tiff",
377
+ ".tiff": "image/tiff",
378
+ ".tr": "application/x-troff",
379
+ ".ts": "video/mp2t",
380
+ ".tsi": "audio/tsp-audio",
381
+ ".tsp": "audio/tsplayer",
382
+ ".tsv": "text/tab-separated-values",
383
+ ".turbot": "image/florian",
384
+ ".txt": "text/plain",
385
+ ".uil": "text/x-uil",
386
+ ".uni": "text/uri-list",
387
+ ".unis": "text/uri-list",
388
+ ".unv": "application/i-deas",
389
+ ".uri": "text/uri-list",
390
+ ".uris": "text/uri-list",
391
+ ".ustar": "application/x-ustar",
392
+ ".uu": "text/x-uuencode",
393
+ ".uue": "text/x-uuencode",
394
+ ".vcd": "application/x-cdlink",
395
+ ".vcs": "text/x-vcalendar",
396
+ ".vda": "application/vda",
397
+ ".vdo": "video/vdo",
398
+ ".vew": "application/groupwise",
399
+ ".viv": "video/vnd.vivo",
400
+ ".vivo": "video/vnd.vivo",
401
+ ".vmd": "application/vocaltec-media-desc",
402
+ ".vmf": "application/vocaltec-media-file",
403
+ ".voc": "audio/x-voc",
404
+ ".vos": "video/vosaic",
405
+ ".vox": "audio/voxware",
406
+ ".vqe": "audio/x-twinvq-plugin",
407
+ ".vqf": "audio/x-twinvq",
408
+ ".vql": "audio/x-twinvq-plugin",
409
+ ".vrml": "x-world/x-vrml",
410
+ ".vrt": "x-world/x-vrt",
411
+ ".vsd": "application/x-visio",
412
+ ".vst": "application/x-visio",
413
+ ".vsw": "application/x-visio",
414
+ ".w60": "application/wordperfect6.0",
415
+ ".w61": "application/wordperfect6.1",
416
+ ".w6w": "application/msword",
417
+ ".wav": "audio/x-wav",
418
+ ".wb1": "application/x-qpro",
419
+ ".wbmp": "image/vnd.wap.wbmp",
420
+ ".web": "application/vnd.xara",
421
+ ".webm": "video/webm",
422
+ ".webp": "image/webp",
423
+ ".wiz": "application/msword",
424
+ ".wk1": "application/x-123",
425
+ ".wmf": "windows/metafile",
426
+ ".wml": "text/vnd.wap.wml",
427
+ ".wmlc": "application/vnd.wap.wmlc",
428
+ ".wmls": "text/vnd.wap.wmlscript",
429
+ ".wmlsc": "application/vnd.wap.wmlscriptc",
430
+ ".word": "application/msword",
431
+ ".woff": "font/woff",
432
+ ".woff2": "font/woff2",
433
+ ".wp": "application/wordperfect",
434
+ ".wp5": "application/wordperfect6.0",
435
+ ".wp6": "application/wordperfect",
436
+ ".wpd": "application/x-wpwin",
437
+ ".wq1": "application/x-lotus",
438
+ ".wri": "application/x-wri",
439
+ ".wrl": "x-world/x-vrml",
440
+ ".wrz": "x-world/x-vrml",
441
+ ".wsc": "text/scriplet",
442
+ ".wsrc": "application/x-wais-source",
443
+ ".wtk": "application/x-wintalk",
444
+ ".xbm": "image/x-xbitmap",
445
+ ".xdr": "video/x-amt-demorun",
446
+ ".xgz": "xgl/drawing",
447
+ ".xif": "image/vnd.xiff",
448
+ ".xl": "application/excel",
449
+ ".xla": "application/x-msexcel",
450
+ ".xlb": "application/vnd.ms-excel",
451
+ ".xlc": "application/x-excel",
452
+ ".xld": "application/x-excel",
453
+ ".xlk": "application/x-excel",
454
+ ".xll": "application/x-excel",
455
+ ".xlm": "application/x-excel",
456
+ ".xls": "application/vnd.ms-excel",
457
+ ".xlt": "application/x-excel",
458
+ ".xlv": "application/x-excel",
459
+ ".xlw": "application/x-msexcel",
460
+ ".xm": "audio/xm",
461
+ ".xml": "text/xml",
462
+ ".xmz": "xgl/movie",
463
+ ".xpix": "application/x-vnd.ls-xpix",
464
+ ".xpm": "image/x-xpixmap",
465
+ ".x-ng": "image/png",
466
+ ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
467
+ ".xsr": "video/x-amt-showrun",
468
+ ".xwd": "image/x-xwindowdump",
469
+ ".xyz": "chemical/x-pdb",
470
+ ".yaml": "application/x-yaml",
471
+ ".yml": "application/x-yaml",
472
+ ".z": "application/x-compressed",
473
+ ".zip": "application/zip",
474
+ ".zoo": "application/octet-stream",
475
+ ".zsh": "text/x-script.zsh",
476
+ ".mjs": "application/javascript",
477
+ ".webmanifest": "application/manifest+json",
478
+ ".dll": "application/octet-stream",
479
+ ".obj": "application/octet-stream",
480
+ ".so": "application/octet-stream",
481
+ ".m3u8": "application/vnd.apple.mpegurl",
482
+ ".wasm": "application/wasm",
483
+ ".h5": "application/x-hdf5",
484
+ ".pfx": "application/x-pkcs12",
485
+ ".pyo": "application/x-python-code",
486
+ ".xsl": "application/xml",
487
+ ".rdf": "application/xml",
488
+ ".wsdl": "application/xml",
489
+ ".xpdl": "application/xml",
490
+ ".3gp": "audio/3gpp",
491
+ ".3gpp": "audio/3gpp",
492
+ ".3g2": "audio/3gpp2",
493
+ ".3gpp2": "audio/3gpp2",
494
+ ".aac": "audio/aac",
495
+ ".adts": "audio/aac",
496
+ ".loas": "audio/aac",
497
+ ".ass": "audio/aac",
498
+ ".opus": "audio/opus",
499
+ ".heic": "image/heic",
500
+ ".heif": "image/heif",
501
+ ".eml": "message/rfc822",
502
+ ".nws": "message/rfc822",
503
+ ".bat": "text/plain",
504
+ ".vcf": "text/x-vcard",
505
+ ".xul": "text/xul",
506
+}
507
+
508
+
509
+def guess(file: t.Union[str, Path]) -> str:
510
+ return _types.get(Path(file).suffix, _default)