MinerUSharp 0.1.2

dotnet add package MinerUSharp --version 0.1.2
                    
NuGet\Install-Package MinerUSharp -Version 0.1.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MinerUSharp" Version="0.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MinerUSharp" Version="0.1.2" />
                    
Directory.Packages.props
<PackageReference Include="MinerUSharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MinerUSharp --version 0.1.2
                    
#r "nuget: MinerUSharp, 0.1.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MinerUSharp@0.1.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MinerUSharp&version=0.1.2
                    
Install as a Cake Addin
#tool nuget:?package=MinerUSharp&version=0.1.2
                    
Install as a Cake Tool

MinerUSharp

Tests NuGet Version NuGet Downloads License: MIT

A C# client library for the self-hosted MinerU API.

Requires a self-hosted MinerU API instance.

See the offical MinerU page for instructions on self-hosting or use the wrapper MinerUHost for automatic setup.

Installation

The easiest way to install and use the MinerUSharp library is through NuGet.

dotnet add package MinerUSharp

That's it! You've now installed MinerUSharp.

Don't forget to also install some way of hosting the MinerU API.

The official page has instructions. You can also use MinerUHost which automates both setup and process management for the underlying Mineru Python service. It is available as a NuGET package and as a prebuilt standalone application through GitHub Releases.

Usage

Basic Usage

Import the following namespaces:

using MinerUSharp;
using MinerUSharp.Models;

Then use it like this:

using MineruClient client = new MineruClient("http://localhost:8080");
using FileStream fileStream = File.OpenRead("document.pdf");

MineruRequest request = new MineruRequest
{
    Files = new[] { fileStream },
    LanguageList = new[] { "en", "ch" },
    StartPageId = 1,
    EndPageId = 10,
    ReturnMarkdown = true,
};

using MineruResponse response = await client.ParseFileAsync(request);
string markdown = await response.ReadAsMarkdownAsync();

Fluent API

You can also use it with fluent API. This example does the same thing as the example above:

using MineruClient client = new MineruClient("http://localhost:8080");
using FileStream fileStream = File.OpenRead("document.pdf");

MineruRequest request = MineruRequest.Create(fileStream)
    .WithLanguages("en", "ch")
    .WithMarkdownResponse()
    .WithPageRange(startPage: 1, endPage: 10)
    .Build();

using MineruResponse response = await client.ParseFileAsync(request);
string markdown = await response.ReadAsMarkdownAsync();

"Advanced Usage"

The quotes are because it's not really that "advanced", but here are some more detailed code snippets:

Dependency Injection

// Program.cs or Startup.cs
services.AddMineruClient("http://localhost:8080");

// In your service
public class DocumentService
{
    private readonly IMineruClient _client;
    
    public DocumentService(IMineruClient client)
    {
        _client = client;
    }
    
    public async Task<string> ParseDocumentAsync(Stream documentStream)
    {
        MineruRequest request = MineruRequest.Create(documentStream)
            .WithMarkdownResponse()
            .Build();
            
        using MineruResponse response = await _client.ParseFileAsync(request);
        return await response.ReadAsMarkdownAsync();
    }
}

Response Options

using MineruResponse response = await client.ParseFileAsync(request);

// Read as markdown (extracts md_content from the JSON response)
string markdown = await response.ReadAsMarkdownAsync();

// Read as strongly-typed response body
MineruResponseBody body = await response.ReadAsResponseBodyAsync();
string markdownFromFirstFile = body.Results["file0"].MarkdownContent;

// Read as raw JSON element
JsonElement json = await response.ReadAsJsonAsync();

// Read as bytes
byte[] bytes = await response.ReadAsBytesAsync();

// Save to file
await response.SaveToFileAsync("output.md");

// Get raw stream for custom processing
Stream stream = response.GetContentStream();

Additional Options

  • The MineruClient constructor accepts an optional HttpClient parameter for custom HTTP client configuration.
  • The ParseFileAsync method accepts an optional CancellationToken parameter for cancellation support.

The underlying MinerU Python API doesn't seem to correctly handle cancelled requests. It seems to continue processing them until they are finished, at least at the time of writing this. The cancellation can still be used to free up your own thread that's calling the Python process, but the Python process will still continue in the background until it's done.

using HttpClient httpClient = new HttpClient();

using MineruClient client = new MineruClient("http://localhost:8080", httpClient);

// The timeout of 5000 ms shown below is very short and not recommended for real scenarios, it's just an example
// that shows that a cancellation token can be sent. It should probably come from a user controlled source.
using CancellationTokenSource cts = new CancellationTokenSource(millisecondsDelay: 5000);
using MineruResponse response = await client.ParseFileAsync(request, cts.Token);

Requirements

  • .NET 8.0 or later
  • MinerU API server that can be accessed
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.2 189 11/5/2025
0.1.1 206 11/4/2025
0.1.0 181 11/4/2025