### Install Test Dependencies and Run Tests Source: https://github.com/mathpix/mpxpy/blob/master/README.md Steps to install dependencies required for running tests and execute the test suite. ```bash # Install test dependencies pip install -e ".[dev]" # Or install using the requirements.txt file pip install -r requirements.txt # Run tests pytest ``` -------------------------------- ### Install mpxpy Source: https://github.com/mathpix/mpxpy/blob/master/README.md Install the mpxpy library using pip. ```bash pip install mpxpy ``` -------------------------------- ### Install mpxpy in Development Mode Source: https://github.com/mathpix/mpxpy/blob/master/README.md How to install the mpxpy library in editable mode for development. ```bash # Install in development mode pip install -e . # Or install using the requirements.txt file pip install -r requirements.txt ``` -------------------------------- ### Get PowerPoint Output Source: https://github.com/mathpix/mpxpy/blob/master/README.md Obtain the PowerPoint output file or bytes. Ensure the output directory exists. ```python pptx_output_path = conversion.to_pptx_file(path='output/sample.pptx') pptx_bytes = conversion.to_pptx_bytes() # is of type bytes ``` -------------------------------- ### Get DOCX Output Source: https://github.com/mathpix/mpxpy/blob/master/README.md Obtain the DOCX output file or bytes. Ensure the output directory exists. ```python docx_output_path = conversion.to_docx_file(path='output/sample.docx') docx_bytes = conversion.to_docx_bytes() # is of type bytes ``` -------------------------------- ### ScsFile Methods Source: https://github.com/mathpix/mpxpy/blob/master/README.md Provides methods to get the status of file processing, wait for completion, retrieve processed data in various formats, and save processed data to local files. ```APIDOC ## ScsFile Methods ### Description Methods to interact with processed file data, including checking status, waiting for completion, retrieving data in various formats (text, bytes, zip), and saving to local files. ### Methods - `status()`: Get the current status of the file processing. Returns details like file_id, status, num_pages, num_pages_completed, percent_done, and formats. - `wait_until_complete()`: Blocks execution until the file processing is fully complete. - `wait_for_format(format)`: Blocks execution until a specific format conversion is complete. - `to_mmd_text()`: Get the processed file result as Mathpix Markdown string. - `to_md_text()`: Get the processed file result as Markdown string. - `to_tex_text()`: Get the processed file result as LaTeX string. - `to_docx_bytes()`: Get the processed file result as DOCX bytes. - `to_xlsx_bytes()`: Get the processed file result as XLSX bytes. - `to_pptx_bytes()`: Get the processed file result as PPTX bytes. - `to_pdf_bytes()`: Get the processed file result as PDF bytes. - `to_latex_pdf_bytes()`: Get the processed file result as LaTeX-rendered PDF bytes. - `to_html_bytes()`: Get the processed file result as HTML bytes. - `to_tex_zip_bytes()`: Get the processed file result as tex.zip bytes. - `to_md_zip_bytes()`: Get the processed file result as md.zip bytes. - `to_mmd_zip_bytes()`: Get the processed file result as mmd.zip bytes. - `to_html_zip_bytes()`: Get the processed file result as html.zip bytes. - `to_jpg_bytes()`: Get the processed file result as JPG bytes. - `to_png_bytes()`: Get the processed file result as PNG bytes. - `to_lines_json()`: Get the processed file result as lines.json. - `to_lines_mmd_json()`: Get the processed file result as lines.mmd.json. - `to_mmd_file(path)`: Save the processed file result to a MMD file at the specified local path. - `to_md_file(path)`: Save the processed file result to a Markdown file at the specified local path. - `to_docx_file(path)`: Save the processed file result to a DOCX file at the specified local path. - `to_xlsx_file(path)`: Save the processed file result to an XLSX file at the specified local path. - `to_pptx_file(path)`: Save the processed file result to a PPTX file at the specified local path. - `to_pdf_file(path)`: Save the processed file result to a PDF file at the specified local path. - `to_html_file(path)`: Save the processed file result to an HTML file at the specified local path. - `to_tex_zip_file(path)`: Save the processed file result to a tex.zip file at the specified local path. - `cropped_image(page, x, y, width, height)`: Get a cropped region from a specific page as JPEG bytes. Parameters: `page` (int), `x` (int), `y` (int), `width` (int), `height` (int). ``` -------------------------------- ### Get Mathpix Markdown ZIP Output Source: https://github.com/mathpix/mpxpy/blob/master/README.md Obtain the Mathpix Markdown ZIP output, which includes embedded images. Ensure the output directory exists. ```python mmd_zip_output_path = conversion.to_mmd_zip_file(path='output/sample.mmd.zip') mmd_zip_bytes = conversion.to_mmd_zip_bytes() # is of type bytes ``` -------------------------------- ### MathpixClient.scs_job_status Source: https://github.com/mathpix/mpxpy/blob/master/README.md Gets the current status of an SCS job. ```APIDOC ## MathpixClient.scs_job_status ### Description Gets the current status of an SCS job. ### Method Not specified (assumed to be a client method call) ### Parameters #### Path Parameters - **scs_job_id** (string) - Required - The job ID to get status for. ### Response Returns JSON response containing job status information. ``` -------------------------------- ### Initialize MathpixClient with Environment Variables Source: https://github.com/mathpix/mpxpy/blob/master/README.md Initialize the MathpixClient using environment variables for authentication. Ensure MATHPIX_APP_ID and MATHPIX_APP_KEY are set. ```python from mpxpy.mathpix_client import MathpixClient # Will use ~/.mpx/config or environment variables client = MathpixClient() ``` -------------------------------- ### Initialize MathpixClient with Arguments Source: https://github.com/mathpix/mpxpy/blob/master/README.md Initialize the MathpixClient by directly passing your App ID and App Key as arguments. ```python from mpxpy.mathpix_client import MathpixClient client = MathpixClient( app_id="your-app-id", app_key="your-app-key" # Optional "api_url" argument sets the base URL. This can be useful for development with on-premise deployments ) ``` -------------------------------- ### Initialize MathpixClient Source: https://github.com/mathpix/mpxpy/blob/master/README.md Instantiate the MathpixClient for making API requests. Authentication can be handled via environment variables if app_id and app_key are not provided. ```python client = MathpixClient(app_id='YOUR_APP_ID', app_key='YOUR_APP_KEY') ``` -------------------------------- ### Initialize MathpixClient Source: https://github.com/mathpix/mpxpy/blob/master/README.md Initializes the MathpixClient. It can use environment variables, a config file, or direct arguments for authentication. The `improve_mathpix` flag can be set to disable output retention. ```APIDOC ## Initialize MathpixClient ### Description Initializes the MathpixClient. It can use environment variables, a config file, or direct arguments for authentication. The `improve_mathpix` flag can be set to disable output retention. ### Method `MathpixClient()` ### Parameters - **app_id** (str) - Optional - Your Mathpix API App ID. - **app_key** (str) - Optional - Your Mathpix API App Key. - **api_url** (str) - Optional - The base URL for the Mathpix API. Defaults to `https://api.mathpix.com`. - **improve_mathpix** (bool) - Optional - If True, Mathpix retains outputs. Defaults to True. ### Request Example ```python from mpxpy.mathpix_client import MathpixClient # Using environment variables or config file client = MathpixClient() # Using arguments client = MathpixClient(app_id="your-app-id", app_key="your-app-key") # Disabling output retention client = MathpixClient(improve_mathpix=False) ``` ``` -------------------------------- ### File Upload and Conversion with Error Handling Source: https://github.com/mathpix/mpxpy/blob/master/README.md Demonstrates how to upload a PDF file for processing and convert it to DOCX format. Includes error handling for file not found and general Mathpix client errors. Also shows how to save the converted DOCX file and handle incomplete conversions. ```python from mpxpy.mathpix_client import MathpixClient from mpxpy.errors import MathpixClientError, ConversionIncompleteError client = MathpixClient(app_id="your-app-id", app_key="your-app-key") try: pdf = client.pdf_new(file_path="example.pdf", convert_to_docx=True) except FileNotFoundError as e: print(f"File not found: {e}") except MathpixClientError as e: print(f"File upload error: {e}") try: pdf.to_docx_file('output/path/example.pdf') except ConversionIncompleteError as e: print(f'Conversions are not complete') ``` -------------------------------- ### Clone mpxpy Repository Source: https://github.com/mathpix/mpxpy/blob/master/README.md Instructions for cloning the mpxpy repository from GitHub. ```bash # Clone the repository git clone git@github.com:Mathpix/mpxpy.git cd mpxpy ``` -------------------------------- ### Initialize MathpixClient with improve_mathpix disabled Source: https://github.com/mathpix/mpxpy/blob/master/README.md Initialize the MathpixClient with the improve_mathpix option set to False to prevent Mathpix from retaining outputs. This setting applies to all requests made with this client. ```python from mpxpy.mathpix_client import MathpixClient client = MathpixClient( improve_mathpix=False ) ``` -------------------------------- ### conversion.to_pptx_bytes Source: https://github.com/mathpix/mpxpy/blob/master/README.md Converts the input to PowerPoint format and returns the output as bytes. ```APIDOC ## conversion.to_pptx_bytes ### Description Converts the input to PowerPoint format and returns the output as bytes. ### Method Not specified (assumed to be a method call on a conversion object) ### Endpoint Not applicable (SDK method) ### Response #### Success Response - **pptx_bytes** (bytes) - The PowerPoint output as a byte string. ``` -------------------------------- ### MathpixClient.batch_new Source: https://github.com/mathpix/mpxpy/blob/master/README.md Submits multiple images for batch processing, returning a Batch instance. ```APIDOC ## MathpixClient.batch_new ### Description Submits multiple images concurrently for processing. This method is designed for handling a collection of image inputs efficiently. ### Method POST (Assumed, based on typical API patterns for batch operations) ### Endpoint `/v4/batch` (Assumed, based on typical API patterns) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - The request body is expected to contain a list of image data or references, along with any processing options applicable to the batch. ### Request Example ```json { "files": [ { "file_path": "/path/to/image1.png" }, { "url": "http://example.com/image2.jpg" } ], "options": { "output_format": "text" } } ``` ### Response #### Success Response (200) - Returns a Batch instance, which likely contains an ID for the batch job and potentially status information. #### Response Example ```json { "batch_id": "batch_abc123", "status": "submitted" } ``` ``` -------------------------------- ### conversion.to_pptx_file Source: https://github.com/mathpix/mpxpy/blob/master/README.md Converts the input to a PowerPoint file and saves it to the specified path. ```APIDOC ## conversion.to_pptx_file ### Description Converts the input to a PowerPoint file and saves it to the specified path. ### Method Not specified (assumed to be a method call on a conversion object) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters - **path** (string) - Required - The output path for the PowerPoint file. ### Request Example ```python pptx_output_path = conversion.to_pptx_file(path='output/sample.pptx') ``` ### Response #### Success Response - **pptx_output_path** (string) - The path to the generated PowerPoint file. ``` -------------------------------- ### conversion.to_mmd_zip_bytes Source: https://github.com/mathpix/mpxpy/blob/master/README.md Converts the input to Mathpix Markdown ZIP format and returns the output as bytes. ```APIDOC ## conversion.to_mmd_zip_bytes ### Description Converts the input to Mathpix Markdown ZIP format (including embedded images) and returns the output as bytes. ### Method Not specified (assumed to be a method call on a conversion object) ### Endpoint Not applicable (SDK method) ### Response #### Success Response - **mmd_zip_bytes** (bytes) - The MMD ZIP output as a byte string. ``` -------------------------------- ### conversion.to_mmd_zip_file Source: https://github.com/mathpix/mpxpy/blob/master/README.md Converts the input to a Mathpix Markdown ZIP file and saves it to the specified path. ```APIDOC ## conversion.to_mmd_zip_file ### Description Converts the input to a Mathpix Markdown ZIP file (including embedded images) and saves it to the specified path. ### Method Not specified (assumed to be a method call on a conversion object) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters - **path** (string) - Required - The output path for the MMD ZIP file. ### Request Example ```python mmd_zip_output_path = conversion.to_mmd_zip_file(path='output/sample.mmd.zip') ``` ### Response #### Success Response - **mmd_zip_output_path** (string) - The path to the generated MMD ZIP file. ``` -------------------------------- ### MathpixClient.pdf_new Source: https://github.com/mathpix/mpxpy/blob/master/README.md Returns a new Pdf instance for processing PDF documents. ```APIDOC ## MathpixClient.pdf_new ### Description Returns a new Pdf instance for processing PDF documents. ### Method (Not specified, assumed to be a client method call) ### Endpoint (Not specified) ### Parameters (None specified) ### Request Example (Not specified) ### Response (Not specified) ``` -------------------------------- ### MathpixClient.conversion_new Source: https://github.com/mathpix/mpxpy/blob/master/README.md Creates a new Conversion instance to convert Mathpix Markdown content into various formats. ```APIDOC ## MathpixClient.conversion_new ### Description Initiates a conversion process for provided Mathpix Markdown (MMD) content, allowing the output to be formatted into several different file types. ### Method POST (Assumed, based on typical API patterns for content conversion) ### Endpoint `/v4/convert` (Assumed, based on typical API patterns) ### Parameters #### Path Parameters None #### Query Parameters - `convert_to_docx` (boolean) - Optional - Convert result to docx. - `convert_to_md` (boolean) - Optional - Convert result to md. - `convert_to_tex_zip` (boolean) - Optional - Convert result to tex.zip. - `convert_to_html` (boolean) - Optional - Convert result to html. - `convert_to_pdf` (boolean) - Optional - Convert result to pdf. - `convert_to_latex_pdf` (boolean) - Optional - Convert result to pdf containing LaTeX. - `convert_to_md_zip` (boolean) - Optional - Convert result to md.zip. - `convert_to_mmd_zip` (boolean) - Optional - Convert result to mmd.zip. - `convert_to_pptx` (boolean) - Optional - Convert result to pptx. - `convert_to_html_zip` (boolean) - Optional - Convert result to html.zip. #### Request Body - `mmd` (string) - Required - Mathpix Markdown content to convert. ### Request Example ```json { "mmd": "# My Document\n\nThis is some \\textbf{bold} text.", "convert_to_html": true } ``` ### Response #### Success Response (200) - The response will contain the converted content in the requested format(s), typically as a downloadable file or a URL to the converted file. #### Response Example ```json { "converted_html": "

My Document

This is some bold text.

" } ``` ``` -------------------------------- ### conversion.to_docx_file Source: https://github.com/mathpix/mpxpy/blob/master/README.md Converts the input to a DOCX file and saves it to the specified path. ```APIDOC ## conversion.to_docx_file ### Description Converts the input to a DOCX file and saves it to the specified path. ### Method Not specified (assumed to be a method call on a conversion object) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters - **path** (string) - Required - The output path for the DOCX file. ### Request Example ```python docx_output_path = conversion.to_docx_file(path='output/sample.docx') ``` ### Response #### Success Response - **docx_output_path** (string) - The path to the generated DOCX file. ``` -------------------------------- ### Process PDF and Convert to Multiple Formats Source: https://github.com/mathpix/mpxpy/blob/master/README.md Process a PDF file and convert it to DOCX, Markdown, and PowerPoint formats. The client automatically waits for processing to complete. ```python from mpxpy.mathpix_client import MathpixClient client = MathpixClient( app_id="your-app-id", app_key="your-app-key" ) # Process a PDF file with multiple conversion formats and options pdf = client.pdf_new( file_path='/path/to/pdf/sample.pdf', convert_to_docx=True, convert_to_md=True, convert_to_pptx=True, convert_to_md_zip=True, # Optional pdf-level improve_mathpix argument is default True ) # Wait for processing to complete. Optional timeout argument is 60 seconds by default. pdf.wait_until_complete(timeout=30) # Get the Markdown outputs md_output_path = pdf.to_md_file(path='output/sample.md') md_text = pdf.to_md_text() # is type str print(md_text) # Get the DOCX outputs docx_output_path = pdf.to_docx_file(path='output/sample.docx') docx_bytes = pdf.to_docx_bytes() # is type bytes # Get the PowerPoint outputs pptx_output_path = pdf.to_pptx_file(path='output/sample.pptx') pptx_bytes = pdf.to_pptx_bytes() # is type bytes # Get the Markdown ZIP outputs (includes embedded images) md_zip_output_path = pdf.to_md_zip_file(path='output/sample.md.zip') md_zip_bytes = pdf.to_md_zip_bytes() # is type bytes # Get the JSON outputs lines_json_output_path = pdf.to_lines_json_file(path='output/sample.lines.json') lines_json = pdf.to_lines_json() # parses JSON into type Dict ``` -------------------------------- ### Conversion Methods Source: https://github.com/mathpix/mpxpy/blob/master/README.md Methods for handling individual document conversions, allowing users to wait for completion, check status, and retrieve results in various formats like DOCX, Markdown, LaTeX, HTML, PDF, and PPTX, either as files or bytes. ```APIDOC ## Conversion Methods ### Description Methods for handling individual document conversions. These methods allow users to wait for the conversion process to complete, check its current status, and retrieve the processed result in various formats. ### Methods - `wait_until_complete`: Wait for the conversion to complete. - `conversion_status`: Get the current status of the conversion. - `to_docx_file`: Save the processed conversion result to a DOCX file at a local path. - `to_docx_bytes`: Get the processed conversion result as DOCX bytes. - `to_md_file`: Save the processed conversion result to a Markdown file at a local path. - `to_md_text`: Get the processed conversion result as a Markdown string. - `to_mmd_file`: Save the processed conversion result to a Mathpix Markdown file at a local path. - `to_mmd_text`: Get the processed conversion result as a Mathpix Markdown string. - `to_tex_zip_file`: Save the processed conversion result to a tex.zip file at a local path. - `to_tex_zip_bytes`: Get the processed conversion result in tex.zip format as bytes. - `to_html_file`: Save the processed conversion result to a HTML file at a local path. - `to_html_bytes`: Get the processed conversion result in HTML format as bytes. - `to_pdf_file`: Save the processed conversion result to a PDF file at a local path. - `to_pdf_bytes`: Get the processed conversion result in PDF format as bytes. - `to_latex_pdf_file`: Save the processed conversion result to a PDF file containing LaTeX at a local path. - `to_latex_pdf_bytes`: Get the processed conversion result in PDF format as bytes (with LaTeX). - `to_md_zip_file`: Save the processed conversion result to a ZIP file containing markdown output and any embedded images. - `to_md_zip_bytes`: Get the processed conversion result in ZIPPED markdown format as bytes. - `to_mmd_zip_file`: Save the processed conversion result to a ZIP file containing Mathpix Markdown output and any embedded images. - `to_mmd_zip_bytes`: Get the processed conversion result in ZIPPED Mathpix Markdown format as bytes. - `to_pptx_file`: Save the processed conversion result to a PPTX file. - `to_pptx_bytes`: Get the processed conversion result in PPTX format as bytes. - `to_html_zip_file`: Save the processed PDF result to a ZIP file containing HTML output and any embedded images. - `to_html_zip_bytes`: Get the processed PDF result in ZIPPED HTML format as bytes. ``` -------------------------------- ### MathpixClient.pdf_new Source: https://github.com/mathpix/mpxpy/blob/master/README.md Processes a PDF file, either from a local path or a URL, with various options for output customization and data extraction. ```APIDOC ## MathpixClient.pdf_new ### Description Processes a PDF file from a local path or URL, allowing for extensive customization of the output, including metadata, alphabet restrictions, formatting options, and conversion to various formats. ### Method POST (Assumed, based on typical API patterns for file uploads and processing) ### Endpoint `/v4/pdf` (Assumed, based on typical API patterns) ### Parameters #### Path Parameters None #### Query Parameters - `alphabets_allowed` (dict) - Optional - List alphabets allowed in the output. - `rm_spaces` (boolean) - Optional - Remove extra white space from equations. - `rm_fonts` (boolean) - Optional - Remove font commands from equations. - `idiomatic_eqn_arrays` (boolean) - Optional - Use aligned, gathered, or cases instead of array environment for equation lists. - `include_equation_tags` (boolean) - Optional - Include equation number tags inside equations LaTeX. - `include_smiles` (boolean) - Optional - Enable experimental chemistry diagram OCR via RDKit normalized SMILES. - `include_chemistry_as_image` (boolean) - Optional - Return an image crop containing SMILES in the alt-text for chemical diagrams. - `include_diagram_text` (boolean) - Optional - Enable text extraction from diagrams. - `numbers_default_to_math` (boolean) - Optional - Specify whether numbers are always math. - `math_inline_delimiters` (tuple[str, str]) - Optional - Specify begin and end inline math delimiters for "text" outputs. - `math_display_delimiters` (tuple[str, str]) - Optional - Specify begin and end display math delimiters for "text" outputs. - `page_ranges` (string) - Optional - Specifies a page range as a comma-separated string (e.g., "2,4-6"). - `enable_spell_check` (boolean) - Optional - Enable a predictive mode for English handwriting. - `auto_number_sections` (boolean) - Optional - Automatically number sections. - `remove_section_numbering` (boolean) - Optional - Remove existing numbering for sections and subsections. - `preserve_section_numbering` (boolean) - Optional - Keep existing section numbering as is. - `enable_tables_fallback` (boolean) - Optional - Enable an advanced table processing algorithm. - `fullwidth_punctuation` (boolean) - Optional - Specify whether punctuation will be fullwidth Unicode. - `convert_to_docx` (boolean) - Optional - Automatically convert your result to docx. - `convert_to_md` (boolean) - Optional - Automatically convert your result to md. - `convert_to_mmd` (boolean) - Optional - Automatically convert your result to mmd. - `convert_to_tex_zip` (boolean) - Optional - Automatically convert your result to tex.zip. - `convert_to_html` (boolean) - Optional - Automatically convert your result to html. - `convert_to_pdf` (boolean) - Optional - Automatically convert your result to pdf. - `convert_to_md_zip` (boolean) - Optional - Automatically convert your result to md.zip. - `convert_to_mmd_zip` (boolean) - Optional - Automatically convert your result to mmd.zip. - `convert_to_pptx` (boolean) - Optional - Automatically convert your result to pptx. - `convert_to_html_zip` (boolean) - Optional - Automatically convert your result to html.zip. - `improve_mathpix` (boolean) - Optional - Enable Mathpix to retain user output. - `file_batch_id` (string) - Optional - Batch ID to associate this file with. #### Request Body - `file_path` (string) - Required - Path to a local PDF file. - `url` (string) - Required - URL of a remote PDF file. - `metadata` (dict) - Optional - Attach metadata to a request. ### Request Example ```json { "file_path": "/path/to/your/document.pdf", "metadata": { "user_id": "12345" } } ``` ### Response #### Success Response (200) - The response structure depends on the conversion options selected. It typically includes the extracted data in various formats (e.g., LaTeX, MathML, text) and potentially converted files. #### Response Example ```json { "data": { "latex_styled": "\\documentclass{article} ...", "text": "The quick brown fox..." }, "converted_files": { "docx": "/path/to/converted.docx" } } ``` ``` -------------------------------- ### MathpixClient.scs_file_new Source: https://github.com/mathpix/mpxpy/blob/master/README.md Uploads a file for asynchronous processing via the files-api v1. Supports various upload modes and extensive conversion options. ```APIDOC ## MathpixClient.scs_file_new ### Description Uploads a file for asynchronous processing via the files-api v1. Supports various upload modes and extensive conversion options. Supports three upload modes (exactly one must be provided): - `file_path`: Multipart upload from local file - `url`: Upload from HTTP URL or S3 presigned URL - `source_s3_uri`: Copy from S3 bucket (requires IAM role access) ### Arguments - `file_path`: Path to a local file to upload. - `url`: URL of a remote file (HTTP/HTTPS or S3 presigned URL). - `source_s3_uri`: S3 URI (s3://bucket/key) to copy from. - `filename`: Optional filename to use (defaults to file basename). - `scs_job_id`: Optional job ID to group files together. - `conversion_formats`: Dict of format names to enable (e.g., `{'mmd': True, 'docx': True}`). - `conversion_options`: Additional conversion options dict. - `destination_s3_uri`: Optional S3 URI to write output files. - `destination_basename`: Optional basename for output files (defaults to file_id). - `s3_region`: Optional AWS region for S3 operations (default us-east-1). - `image_output_mode`: Image output mode (e.g., 'local' to upload to destination_s3_uri). - `include_page_info`: Include page info in output (default None). - `metadata`: Optional dict to attach metadata to the request. - `alphabets_allowed`: Optional dict to list alphabets allowed in the output. - `rm_spaces`: Remove extra white space from equations (default True). - `rm_fonts`: Remove font commands from equations (default False). - `idiomatic_eqn_arrays`: Use aligned/gathered/cases instead of array (default False). - `include_equation_tags`: Include equation number tags in LaTeX (default False). - `include_smiles`: Enable chemistry diagram OCR via SMILES (default True). - `include_chemistry_as_image`: Return image crop for chemical diagrams (default False). - `include_diagram_text`: Enable text extraction from diagrams (default False). - `numbers_default_to_math`: Numbers are always math (default False). - `math_inline_delimiters`: Tuple of (begin, end) delimiters for inline math. - `math_display_delimiters`: Tuple of (begin, end) delimiters for display math. - `page_ranges`: Page range string (e.g., "2,4-6" or "2--2"). - `enable_spell_check`: Enable predictive mode for English handwriting (default False). - `auto_number_sections`: Auto-number sections (default False). - `remove_section_numbering`: Remove existing section numbering (default False). - `preserve_section_numbering`: Keep existing section numbering (default True). - `enable_tables_fallback`: Enable advanced table processing (default False). - `fullwidth_punctuation`: Use fullwidth Unicode punctuation (default None). ``` -------------------------------- ### conversion.to_docx_bytes Source: https://github.com/mathpix/mpxpy/blob/master/README.md Converts the input to DOCX format and returns the output as bytes. ```APIDOC ## conversion.to_docx_bytes ### Description Converts the input to DOCX format and returns the output as bytes. ### Method Not specified (assumed to be a method call on a conversion object) ### Endpoint Not applicable (SDK method) ### Response #### Success Response - **docx_bytes** (bytes) - The DOCX output as a byte string. ``` -------------------------------- ### MathpixClient.query_usage Source: https://github.com/mathpix/mpxpy/blob/master/README.md Queries API usage statistics. ```APIDOC ## MathpixClient.query_usage ### Description Queries API usage statistics. ### Method Not specified (assumed to be a client method call) ### Parameters #### Query Parameters - **from_date** (string) - Required - Start date for usage query (ISO 8601 format). - **to_date** (string) - Required - End date for usage query (ISO 8601 format). - **app_id** (string) - Optional - Filter by application ID. - **usage_type** (string) - Optional - Filter by usage type (e.g., 'image', 'pdf-page', 'strokes-session'). - **request_args_hash** (string) - Optional - Filter by request args hash. - **timespan** (string) - Optional - Aggregation period ('hour', 'day', 'month', 'year'). - **group_by** (array) - Optional - Fields to group by (['app_id', 'usage_type', 'request_args_hash']). - **page** (integer) - Optional - Page number (1-100, default 1). - **per_page** (integer) - Optional - Results per page (1-1000, default 100). ### Response Returns a dict with 'ocr_usage' list containing usage records. ``` -------------------------------- ### MathpixClient.batch_new Source: https://github.com/mathpix/mpxpy/blob/master/README.md Processes a batch of images from provided URLs. Supports various configurations for OCR behavior, callbacks, metadata, and output formats. ```APIDOC ## MathpixClient.batch_new ### Description Processes a batch of images from provided URLs. Supports various configurations for OCR behavior, callbacks, metadata, and output formats. ### Arguments - `urls`: Dict mapping keys to image sources. Values can be string URLs, data URLs, or objects with per-item options. - `ocr_behavior`: Processing mode - "latex" (default) or "text". - `callback`: Optional callback configuration for async notification. - `metadata`: Optional metadata dict to attach to the request. - `formats`: Optional list of output formats (applies to all items unless overridden). - `data_options`: Optional DataOptions dict for text mode. - `include_detected_alphabets`: Return detected alphabets in results. - `alphabets_allowed`: Dict specifying allowed alphabets. - `confidence_threshold`: File-level confidence threshold (0-1). - `confidence_rate_threshold`: Symbol-level confidence threshold (0-1). ``` -------------------------------- ### MathpixClient.list_scs_jobs Source: https://github.com/mathpix/mpxpy/blob/master/README.md Lists SCS jobs from files-api v1. ```APIDOC ## MathpixClient.list_scs_jobs ### Description Lists SCS jobs from files-api v1. ### Method Not specified (assumed to be a client method call) ### Parameters #### Query Parameters - **start** (string) - Optional - Optional start date filter (ISO format). - **end** (string) - Optional - Optional end date filter (ISO format). - **limit** (integer) - Optional - Maximum number of results (default 100). - **paging_state** (string) - Optional - Optional paging state for pagination. ### Response Returns a dict containing 'jobs' list and optionally 'paging_state' for next page. ``` -------------------------------- ### MathpixClient.app_token_new Source: https://github.com/mathpix/mpxpy/blob/master/README.md Creates a new app token for client-side authentication. Supports configuration for expiration and stroke session ID inclusion. ```APIDOC ## MathpixClient.app_token_new ### Description Creates a new app token for client-side authentication. Supports configuration for expiration and stroke session ID inclusion. ### Arguments - `expires`: Token expiration in seconds (30-43200, default 300). If include_strokes_session_id is True, max is 300. - `include_strokes_session_id`: If True, creates a strokes session and returns strokes_session_id. - `user_id`: Optional user ID to associate with this token. ``` -------------------------------- ### MathpixClient.app_token_get Source: https://github.com/mathpix/mpxpy/blob/master/README.md Retrieves information about a specific app token. ```APIDOC ## MathpixClient.app_token_get ### Description Retrieves information about a specific app token. ### Arguments - `app_token`: The app token to query. ``` -------------------------------- ### MathpixClient.list_scs_files Source: https://github.com/mathpix/mpxpy/blob/master/README.md Lists files from the files-api v1. Requires exactly one filter: scs_job_id or filename. ```APIDOC ## MathpixClient.list_scs_files ### Description Lists files from the files-api v1. Requires exactly one filter: scs_job_id or filename. ### Method Not specified (assumed to be a client method call) ### Parameters #### Query Parameters - **scs_job_id** (string) - Required - Filter by job ID. - **filename** (string) - Required - Filter by filename. - **limit** (integer) - Optional - Maximum number of results (default 100). - **paging_state** (string) - Optional - Optional paging state for pagination. ### Response Returns a dict containing 'file_ids' list and 'next_page_token' for pagination. ``` -------------------------------- ### Convert Mathpix Markdown (MMD) to Other Formats Source: https://github.com/mathpix/mpxpy/blob/master/README.md Convert Mathpix Markdown (MMD) content into DOCX, Markdown, and PowerPoint formats. The client waits for the conversion to complete. ```python from mpxpy.mathpix_client import MathpixClient client = MathpixClient( app_id="your-app-id", app_key="your-app-key" ) # Similar to Pdf, Conversion class takes separate arguments for each conversion format conversion = client.conversion_new( mmd="\frac{1}{2} + \sqrt{3}", convert_to_docx=True, convert_to_md=True, convert_to_mmd_zip=True, convert_to_pptx=True, ) # Wait for conversion to complete conversion.wait_until_complete(timeout=30) # Get the Markdown outputs md_output_path = conversion.to_md_file(path='output/sample.md') md_text = conversion.to_md_text() # is of type str ``` -------------------------------- ### Process Image with Options Source: https://github.com/mathpix/mpxpy/blob/master/README.md Process an image file with additional options such as tags or including line data. Each call creates a new image processing request. ```python from mpxpy.mathpix_client import MathpixClient client = MathpixClient( app_id="your-app-id", app_key="your-app-key" ) # Process an image file with various options tagged_image = client.image_new( file_path='/path/to/image/sample.jpg', tags=['tag'] ) include_line_data = client.image_new( file_path='/path/to/image/sample.jpg', include_line_data=True ) ``` -------------------------------- ### Make Asynchronous Image Request Source: https://github.com/mathpix/mpxpy/blob/master/README.md Make an asynchronous image request and wait for its completion. This is useful for long-running processing tasks. ```python from mpxpy.mathpix_client import MathpixClient client = MathpixClient( app_id="your-app-id", app_key="your-app-key" ) # Make an async image request and get its results async_image = client.image_new( file_path='/path/to/image/sample.jpg', is_async=True ) async_image.wait_until_complete(timeout=5) result = async_image.results() ``` -------------------------------- ### MathpixClient.image_new Source: https://github.com/mathpix/mpxpy/blob/master/README.md Processes an image file or URL to extract mathematical and textual content. Supports various options for output formats, metadata, and advanced processing. ```APIDOC ## MathpixClient.image_new ### Description Processes an image file or URL to extract mathematical and textual content. Supports various options for output formats, metadata, and advanced processing. ### Method (Not specified, assumed to be a client method call) ### Parameters #### Path Parameters (None specified) #### Query Parameters (None specified) #### Request Body (None specified) ### Arguments - **file_path** (string) - Path to a local image file. - **url** (string) - URL of a remote image. - **improve_mathpix** (boolean) - Optional: Enable Mathpix to retain user output. - **metadata** (dict) - Optional: Attach metadata to a request. - **tags** (list[string]) - Optional: Identify results using the /v3/ocr-results endpoint. - **is_async** (boolean) - Optional: Enable non-interactive requests. - **callback** (Callback Object) - Optional: Callback Object (see [Callback Object](https://docs.mathpix.com/#callback-object)). - **formats** (list[string]) - Optional: List of formats ('text', 'data', 'html', or 'latex_styled'). - **data_options** (dict) - Optional: DataOptions dict (see [DataOptions Object](https://docs.mathpix.com/#dataoptions-object)). - **include_detected_alphabets** (boolean) - Optional: Return the detected alphabets. - **alphabets_allowed** (dict) - Optional: List alphabets allowed in the output (see [AlphabetsAllowed Object](https://docs.mathpix.com/#alphabetsallowed-object)). - **region** (dict) - Optional: Specify the image area with pixel coordinates 'top_left_x', 'top_left_y', 'width', 'height'. - **enable_blue_hsv_filter** (boolean) - Optional: Enable a special mode of image processing where it processes blue hue text exclusively. - **confidence_threshold** (number) - Optional: Between 0 and 1 to specify a threshold for triggering confidence errors (file level threshold). - **confidence_rate_threshold** (number) - Optional: Between 0 and 1 to specify a threshold for triggering confidence errors, default 0.75 (symbol level threshold). - **include_equation_tags** (boolean) - Optional: Specify whether to include equation number tags inside equations LaTeX. - **include_line_data** (boolean) - Optional: Return information segmented line by line. - **include_word_data** (boolean) - Optional: Return information segmented word by word. - **include_smiles** (boolean) - Optional: Enable experimental chemistry diagram OCR via RDKIT normalized SMILES. - **include_inchi** (boolean) - Optional: Include InChI data as XML attributes inside `` elements. - **include_geometry_data** (boolean) - Optional: Enable data extraction for geometry diagrams (currently only supports triangle diagrams). - **include_diagram_text** (boolean) - Optional: Enable text extraction from diagrams. - **auto_rotate_confidence_threshold** (number) - Optional: Between 0 and 1 to specify threshold for auto rotating images to the correct orientation, default 0.99. - **rm_spaces** (boolean) - Optional: Determine whether extra white space is removed from equations. - **rm_fonts** (boolean) - Optional: Determine whether font commands are removed from equations. - **idiomatic_eqn_arrays** (boolean) - Optional: Specify whether to use aligned, gathered, or cases instead of an array environment for a list of equations. - **idiomatic_braces** (boolean) - Optional: Specify whether to remove unnecessary braces for LaTeX output. - **numbers_default_to_math** (boolean) - Optional: Specify whether numbers are always math. - **math_fonts_default_to_math** (boolean) - Optional: Specify whether math fonts are always math. - **math_inline_delimiters** (tuple[str, str]) - Optional: Specify begin and end inline math delimiters for "text" outputs. - **math_display_delimiters** (tuple[str, str]) - Optional: Specify begin and end display math delimiters for "text" outputs. - **enable_spell_check** (boolean) - Optional: Enable a predictive mode for English handwriting. - **enable_tables_fallback** (boolean) - Optional: Enable an advanced table processing algorithm. - **fullwidth_punctuation** (boolean) - Optional: Specify whether punctuation will be fullwidth Unicode. ### Request Example (Not specified) ### Response (Not specified) ``` -------------------------------- ### Batch Methods Source: https://github.com/mathpix/mpxpy/blob/master/README.md Methods for managing batch processing of multiple documents. Users can check the batch status, wait for all items to complete, and retrieve the results for each processed item. ```APIDOC ## Batch Methods ### Description Methods for managing batch processing of multiple documents. These methods allow users to check the status of the entire batch, wait for all individual items within the batch to finish processing, and retrieve the results for each item. ### Methods - `status`: Get the current status of the batch, including keys and results. - `wait_until_complete`: Wait for all items in the batch to complete processing. - `results`: Get the results dict mapping url_key to OCR result for each processed item. - `keys`: Get the list of URL keys in this batch. ``` -------------------------------- ### Set Logging Level for mpxpy Source: https://github.com/mathpix/mpxpy/blob/master/README.md Configures the logging level for mpxpy by setting the MATHPIX_LOG_LEVEL environment variable. DEBUG logs all events, while INFO logs events excluding polling. ```bash MATHPIX_LOG_LEVEL=DEBUG ``` -------------------------------- ### Process Image File Source: https://github.com/mathpix/mpxpy/blob/master/README.md Process a single image file using the Mathpix API. The default improve_mathpix setting is True. ```python from mpxpy.mathpix_client import MathpixClient client = MathpixClient( app_id="your-app-id", app_key="your-app-key" ) # Process an image file image = client.image_new( file_path='/path/to/image/sample.jpg', # Optional image-level improve_mathpix argument is default True ) ``` -------------------------------- ### Convert Mathpix Markdown (MMD) Source: https://github.com/mathpix/mpxpy/blob/master/README.md Converts Mathpix Markdown (MMD) content into various formats. Supports multiple conversion options and asynchronous processing. ```APIDOC ## Convert Mathpix Markdown (MMD) ### Description Converts Mathpix Markdown (MMD) content into various formats. Supports multiple conversion options and asynchronous processing. ### Method `client.conversion_new()` ### Parameters - **mmd** (str) - Required - The Mathpix Markdown content to convert. - **convert_to_docx** (bool) - Optional - Whether to convert to DOCX format. - **convert_to_md** (bool) - Optional - Whether to convert to Markdown format. - **convert_to_mmd_zip** (bool) - Optional - Whether to convert to a ZIP archive of MMD files. - **convert_to_pptx** (bool) - Optional - Whether to convert to PowerPoint format. ### Request Example ```python conversion = client.conversion_new( mmd="\frac{1}{2} + \sqrt{3}", convert_to_docx=True, convert_to_md=True, convert_to_mmd_zip=True, convert_to_pptx=True ) ``` ## Wait for MMD Conversion ### Description Waits for the MMD conversion to complete. An optional timeout can be specified. ### Method `conversion.wait_until_complete()` ### Parameters - **timeout** (int) - Optional - The timeout in seconds. Defaults to 30. ### Request Example ```python conversion.wait_until_complete(timeout=30) ``` ## Get MMD Conversion Outputs ### Description Retrieves the converted MMD content in various formats. ### Methods - `conversion.to_md_file(path)`: Saves Markdown output to a file. - `conversion.to_md_text()`: Returns Markdown output as a string. ### Request Example ```python md_output_path = conversion.to_md_file(path='output/sample.md') md_text = conversion.to_md_text() ``` ```