ModrinthSharp 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ModrinthSharp --version 1.0.0
                    
NuGet\Install-Package ModrinthSharp -Version 1.0.0
                    
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="ModrinthSharp" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ModrinthSharp" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ModrinthSharp" />
                    
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 ModrinthSharp --version 1.0.0
                    
#r "nuget: ModrinthSharp, 1.0.0"
                    
#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 ModrinthSharp@1.0.0
                    
#: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=ModrinthSharp&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ModrinthSharp&version=1.0.0
                    
Install as a Cake Tool

ModrinthSharp

ModrinthSharp is a .NET 8 library for accessing the Modrinth API in C#. It provides easy-to-use methods for searching, retrieving, and analyzing Modrinth projects, versions, users, teams, dependencies, and files.

Features

  • Search for Modrinth projects with advanced filters
  • Get detailed project info by ID or slug
  • List all versions of a project
  • Get version details and files
  • Download project files
  • Get user and team info
  • Fetch project dependencies
  • Strongly-typed models for all major Modrinth API objects
  • Robust error handling with API error details

Installation

Add the ModrinthSharp project to your solution or reference the DLL. Target .NET 8 or later.

Usage

Creating a Client

Create an instance of the client:

using ModrinthSharp;

var modrinth = new ModrinthSharp();

Async Usage

All methods are async. Use them in an async context:

using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        var modrinth = new ModrinthSharp();
        // ... call methods below ...
    }
}

Search for Projects

Search for projects by keyword:

var results = await modrinth.SearchProjectsAsync("sodium");
foreach (var project in results.Hits)
{
    Console.WriteLine($"{project.Title} ({project.Slug})");
}

Search with filters (categories, loaders, game versions):

var advanced = await modrinth.SearchProjectsAdvancedAsync(
    query: "optimization",
    categories: new[] { "performance" },
    loaders: new[] { "fabric" },
    gameVersions: new[] { "1.20.1" }
);
foreach (var project in advanced.Hits)
{
    Console.WriteLine($"{project.Title} - {project.Downloads} downloads");
}

Get Project by ID or Slug

Get detailed info for a project:

var project = await modrinth.GetProjectAsync("sodium");
Console.WriteLine($"{project.Title}: {project.Description}");

List Project Versions

Get all versions for a project:

var versions = await modrinth.GetProjectVersionsAsync("sodium");
foreach (var version in versions)
{
    Console.WriteLine($"{version.Name} ({version.VersionNumber})");
}

Get Version Details and Files

Get details and files for a specific version:

var version = await modrinth.GetVersionAsync(versions[0].Id);
var files = await modrinth.GetVersionFilesAsync(version.Id);
foreach (var file in files)
{
    Console.WriteLine($"File: {file.Filename} ({file.Size} bytes)");
}

Download a File

Download a file to disk:

await modrinth.DownloadFileAsync(files[0].Url, @"C:\\Downloads\\" + files[0].Filename);

Get User and Team Info

Get user and team details:

var user = await modrinth.GetUserAsync("johndoe");
Console.WriteLine($"User: {user.Username} ({user.Id})");

var team = await modrinth.GetTeamAsync("teamid");
Console.WriteLine($"Team: {team.Name}");
### Get Project Dependencies
List dependencies for a project:var dependencies = await modrinth.GetProjectDependenciesAsync("sodium");
foreach (var dep in dependencies)
{
    Console.WriteLine($"Depends on: {dep.ProjectId} ({dep.DependencyType})");
}

Error Handling

All methods throw ModrinthApiException on API errors, which includes the HTTP status and any error message from Modrinth.

Example:

try
{
    var project = await modrinth.GetProjectAsync("nonexistent_project");
}
catch (ModrinthApiException ex)
{
    Console.WriteLine($"API Error: {ex.StatusCode} - {ex.ApiError}");
}

Complete Example

A typical workflow:

using ModrinthSharp;
using System;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        var modrinth = new ModrinthSharp();
        var results = await modrinth.SearchProjectsAsync("sodium");
        var project = await modrinth.GetProjectAsync(results.Hits[0].Slug);
        var versions = await modrinth.GetProjectVersionsAsync(project.Id);
        var version = await modrinth.GetVersionAsync(versions[0].Id);
        var files = await modrinth.GetVersionFilesAsync(version.Id);
        await modrinth.DownloadFileAsync(files[0].Url, @"C:\\Downloads\\" + files[0].Filename);
        Console.WriteLine($"Downloaded {files[0].Filename} for {project.Title}");
    }
}

Model Reference

  • ModrinthProject: All project metadata (title, description, downloads, categories, etc.)
  • ModrinthVersion: Version info (name, changelog, supported game versions, loaders, etc.)
  • ModrinthFile: File info (filename, size, URL, hashes, etc.)
  • User, Team: User/team info
  • Dependency: Project dependencies
  • SearchResult: Search results (list of projects, total hits, etc.)

License

MIT

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.
  • net8.0

    • No dependencies.

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
1.1.0 136 7/9/2025
1.0.0 90 6/29/2025