MagikaSharp 9.0.2
dotnet add package MagikaSharp --version 9.0.2
NuGet\Install-Package MagikaSharp -Version 9.0.2
<PackageReference Include="MagikaSharp" Version="9.0.2" />
<PackageVersion Include="MagikaSharp" Version="9.0.2" />
<PackageReference Include="MagikaSharp" />
paket add MagikaSharp --version 9.0.2
#r "nuget: MagikaSharp, 9.0.2"
#:package MagikaSharp@9.0.2
#addin nuget:?package=MagikaSharp&version=9.0.2
#tool nuget:?package=MagikaSharp&version=9.0.2
π¦ MagikaSharp
MagikaSharp is an unofficial .NET wrapper for Googleβs magika file type detection system. It provides a clean and safe C# API on top of a high-performance Rust FFI integration using ONNX Runtime.
MagikaSharp brings Magikaβs machine-learning-powered file type identification to the .NET ecosystem, supporting:
- β Windows
- β Linux
- β macOS (Apple Silicon)
β¨ Features
- π Fast and accurate file type detection
- π Detailed metadata (label, mime, description, extensions, category, text/binary flag)
- β‘ High-performance Rust backend with native ONNX Runtime
- π§΅ Safe managed API with automatic memory handling
- π¦ Cross-platform native runtime packing (NuGet-friendly)
π₯ Installation
Install from NuGet:
dotnet add package MagikaSharp
π Quick Example
using MagikaSharp;
using var magika = new MagikaSession();
var info = magika.IdentifyFile("example.pdf");
Console.WriteLine($"Label: {info.Label}");
Console.WriteLine($"MIME: {info.MimeType}");
Console.WriteLine($"Group: {info.Group}");
Console.WriteLine($"Description: {info.Description}");
Console.WriteLine("Extensions: " + string.Join(", ", info.Extensions));
Console.WriteLine($"IsText: {info.IsText}");
π API Highlights
Identify a file
var info = magika.IdentifyFile("file.bin");
Identify in-memory bytes
var info = magika.IdentifyBytes(data);
Returned info object
public sealed class MagikaTypeInfo
{
public string Label { get; }
public string MimeType { get; }
public string Group { get; }
public string Description { get; }
public string[] Extensions { get; }
public bool IsText { get; }
}
βοΈ How It Works
MagikaSharp ships with:
- Native Rust library (
libmagika_ffi) - Bundled ONNX Runtime dependencies
- A thin and safe C# P/Invoke layer
- A high-level managed API class (
MagikaSession)
At runtime, MagikaSharp dynamically loads the correct native library based on the current platform.
π Notes
MagikaSharp is not affiliated with Google. Magika is a Google project released under the Apache 2.0 license.
This library aims to:
- provide reliable .NET bindings
- support Linux/Windows/macOS
- make Magika easy to consume in .NET apps and services
This project includes components from:
- Google Magika (Apache License 2.0)
- ONNX Runtime (MIT License)
MagikaSharp is an independent project and is not affiliated with Google.
π€ Contributing
PRs, issue reports, and suggestions are welcome!
π License
- MIT
- Magika itself is Apache 2.0.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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. |
-
net9.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.