Django automatically adding ".xlsx" to mimetypes types_map

Hi all,

Python’s built-in mimetypes library has a method types_map(), which returns a mapping of filename extensions → MIME type. The mapping looks like {'.js': 'application/javascript', '.mpeg': 'video/mpeg', ...}.

I’ve noticed that when using a vanilla Python shell there is no mapping for .xlsx, but when using Django’s shell (python manage.py shell) there is.

Repo steps:

In vanilla Python shell:

import mimetypes
print(mimetypes.types_map[".xlsx"]) # Errors

In Django shell:

import mimetypes
print(mimetypes.types_map[".xlsx"]) # Prints "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

Django Version: 4.2
Python Version: 3.11.10 (I also tried 3.8)

Mimetypes does provide the add_types() method which adds a new extension to the mapping. However, I could not find anything in the Django source code using it or otherwise affecting the mapping.

Any ideas about where this .xlsx mapping is coming from?

When you use the Django shell, does your environment include any other extra modules besides Django?

Good call, that was it. It looks like the openpyxl package adds some file extensions to the mapping when initialized. Thanks for the help.