innobrain / markitdown
Laravel bindings for markitdown.
Fund package maintenance!
Innobrain
Requires
- php: ^8.3
- illuminate/contracts: ^10.0||^11.0
- kauffinger/pyman: ^0.0.2
- spatie/laravel-package-tools: ^1.16
- spatie/temporary-directory: ^2.2
Requires (Dev)
- larastan/larastan: ^3
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^2.0.0
- phpstan/phpstan-phpunit: ^2.0.0
- rector/rector: ^2.0
README
Laravel bindings for markitdown.
Installation
- Install the package via composer:
composer require innobrain/markitdown
- Publish the configuration file:
php artisan vendor:publish --tag="markitdown-config"
- Run the installation command if you want the package to manage your
markitdown
installation:
php artisan markitdown:install
This will:
- Set up a Python virtual environment with the required dependencies
- Add the setup script to your project's composer.json
- Ensure the environment is kept up to date with future composer updates
Alternative Installation Methods
If you prefer not to use the built-in virtual environment, you can disable it in your .env
file or in the config:
MARKITDOWN_USE_VENV_PACKAGE=false
Then install markitdown manually using one of these methods:
Using pip directly:
pip install markitdown
Using pipx (Recommended for manual installation):
On macOS:
brew install pipx
pipx ensurepath
sudo pipx ensurepath --global # optional to allow pipx actions with --global argument
Or see how to install on other platforms.
After installing pipx
, you can install markitdown
with:
pipx install markitdown
When not using the built-in virtual environment, you'll need to set the path to the markitdown
executable in your .env
file. You can retrieve the path with:
which markitdown
MARKITDOWN_EXECUTABLE=/path/to/markitdown
Also, when running the script anywhere but the console, you need to set the PATH, as php-fpm does not have
access to the PATH variable. You can do this by adding the following to your .env
file:
MARKITDOWN_SYSTEM_PATH=<your path>
Configuration
The package's configuration will be published to config/markitdown.php
. Here are the available options:
return [ /* * Use this to set the timeout for the process. Default is 30 seconds. */ 'process_timeout' => env('MARKITDOWN_PROCESS_TIMEOUT', 30), /* * Use this to set the path to the markitdown executable. If not set, * the binary will be searched in the PATH. Will be ignored * if use_venv_package is set to true. */ 'executable' => env('MARKITDOWN_EXECUTABLE', 'markitdown'), /* * This will override the above setting and use the new locally installed package. */ 'use_venv_package' => env('MARKITDOWN_USE_VENV_PACKAGE', true), /* * This is needed when you want to run markitdown in php-fpm. One dependency * of markitdown requires PATH to be set. If you are running in a console, * this is not needed. */ 'system' => [ 'path' => env('MARKITDOWN_SYSTEM_PATH', ''), ], /* * The path where temporary files will be stored. This directory must be writable * by the web server. Defaults to storage/app/private/markitdown_tmp */ 'temporary_directory' => env('MARKITDOWN_TEMPORARY_DIRECTORY', storage_path('app/private/markitdown_tmp')), ];
Usage
// convert a file: $markdown = \Innobrain\Markitdown\Facades\Markitdown::convert('/path/to/file.docx'); // or convert a file you already have in memory: $file = file_get_contents('/path/to/file.docx'); $markdown = \Innobrain\Markitdown\Facades\Markitdown::convertFile($file, '.docx');
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.