Skip to main content
The 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 be None, 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").
Detected from:
  • HTTP Content-Type header
  • File extension guessing
  • Magika content analysis
  • Data URI scheme

extension

str | None
File extension including the leading dot (e.g., ".pdf", ".docx", ".html").
Detected from:
  • Local file path
  • URL path
  • HTTP Content-Disposition header filename
  • MIME type guessing

charset

str | None
Character encoding (e.g., "utf-8", "iso-8859-1", "windows-1252").
Detected from:
  • HTTP Content-Type header
  • Data URI attributes
  • charset_normalizer analysis for text files

filename

str | None
Original filename (e.g., "report.pdf", "data.json").
Detected from:
  • Local file path (basename)
  • HTTP Content-Disposition header
  • URL path (if it looks like a file)

local_path

str | None
Full path to the file on disk if read from local filesystem.
Only set when using:
  • convert_local()
  • convert() with a local path
  • convert_uri() with file:// scheme

url

str | None
Source URL if the file was fetched from the web.
Set when using:
  • convert_url() / convert_uri() with HTTP(S) URLs
  • convert_response() (from response.url)
  • Manually via stream_info parameter

Methods

copy_and_update()

Create a copy of the StreamInfo with updated fields. Non-None values from arguments override existing values.
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