StreamInfo class stores metadata about a file stream, including mimetype, extension, charset, and source information. It’s used throughout MarkItDown to help converters identify and process files correctly.
Overview
StreamInfo is a frozen dataclass that contains optional metadata fields. All fields can beNone, depending on how the stream was opened and what information is available.
Fields
mimetype
str | None
MIME type of the file (e.g.,
"application/pdf", "text/html", "image/png").- HTTP
Content-Typeheader - File extension guessing
- Magika content analysis
- Data URI scheme
extension
str | None
File extension including the leading dot (e.g.,
".pdf", ".docx", ".html").- Local file path
- URL path
- HTTP
Content-Dispositionheader filename - MIME type guessing
charset
str | None
Character encoding (e.g.,
"utf-8", "iso-8859-1", "windows-1252").- HTTP
Content-Typeheader - Data URI attributes
- charset_normalizer analysis for text files
filename
str | None
Original filename (e.g.,
"report.pdf", "data.json").- Local file path (basename)
- HTTP
Content-Dispositionheader - URL path (if it looks like a file)
local_path
str | None
Full path to the file on disk if read from local filesystem.
convert_local()convert()with a local pathconvert_uri()withfile://scheme
url
str | None
Source URL if the file was fetched from the web.
convert_url()/convert_uri()with HTTP(S) URLsconvert_response()(fromresponse.url)- Manually via stream_info parameter
Methods
copy_and_update()
StreamInfo
One or more StreamInfo instances to merge. Later arguments take precedence.
dict
Individual field values to update (mimetype, extension, etc.).
StreamInfo
New StreamInfo instance with merged values.
Example
Merging Multiple StreamInfo Objects
Usage Examples
Basic Creation
With Conversion Methods
Override Detected Metadata
In Custom Converters
Metadata Detection
Automatic Detection Flow
MarkItDown automatically builds StreamInfo through multiple detection stages:Magika Enhancement
MarkItDown uses Magika to analyze file content and enhance metadata:Common Patterns
Check Available Metadata
Handle Missing Metadata
Build StreamInfo Incrementally
See Also
- DocumentConverter - Uses StreamInfo to determine file handling
- MarkItDown.convert() - Accepts optional StreamInfo parameter
- DocumentConverterResult - Result type from conversions