Skip to content

feat(magika): make magika an optional dependency - #1355

Open
SyedaAnshrahGillani (SyedaAnshrahGillani) wants to merge 4 commits into
microsoft:mainfrom
SyedaAnshrahGillani:fix/onnxruntime-dependency
Open

SyedaAnshrahGillani (SyedaAnshrahGillani) wants to merge 4 commits into
microsoft:mainfrom
SyedaAnshrahGillani:fix/onnxruntime-dependency

Conversation

@SyedaAnshrahGillani

Copy link
Copy Markdown

Description:

This pull request makes the magika library an optional dependency in the markitdown package.
Previously, magika (and its dependency onnxruntime) was a mandatory installation, even for users who
did not utilize its functionality.

By making magika optional, users can now choose to install it only if they require its features,
leading to a smaller and more efficient installation for most users.

Changes:

  • packages/markitdown/pyproject.toml: Moved onnxruntime into a new optional dependency group magika.
  • packages/markitdown/src/markitdown/_markitdown.py:
    • Removed the direct import of magika.
    • Implemented a conditional import for magika within the MarkItDown class's init method.
    • Added a check in _get_stream_info_guesses to ensure magika is available before attempting to use
      it, gracefully skipping its functionality if not installed.

@SyedaAnshrahGillani

Copy link
Copy Markdown
Author

SyedaAnshrahGillani (@SyedaAnshrahGillani) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

@josteink

Copy link
Copy Markdown

Of all PRs I'd like to see merged for this repo, this is the one I definitely would like to see merged the most.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@josteink

Jostein Kjønigsen (josteink) commented Dec 15, 2025 •

Copy link
Copy Markdown

Could this PR get some love, pretty please? Adam Fourney (@afourney)

Calling in a favour as a .NET member and otherwise MS champion in GNU Emacs 😄

@Sillocan

Copy link
Copy Markdown

Could we please get this merged so we can use magika 1.x with libraries that use this :(

@ranma42

Copy link
Copy Markdown

I believe this fixes/implements:

@armujahid Abdul Rauf (armujahid) left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now conflicts with main; please update it.

Please also fix the duplicate [project.optional-dependencies] table, which makes the TOML invalid, and include Magika in [all].

Making Magika optional makes sense, but when no converter accepts a stream and Magika isn't installed, please add guidance to the UnsupportedFormatException suggesting markitdown[magika] or explicit format information. ImportWarning is hidden by default, so it doesn't provide that guidance. Conversions that can succeed without Magika should keep working.

Please add tests with and without Magika, including streams without format hints and charset handling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants