Introducing DotNetPy: Python Interop for Modern .NET,…
    Neura MarketNeura Market/DeepSeek
    ChatGPTChatGPTClaudeClaudeGeminiGeminiCursorCursorGrokGrokPerplexityPerplexityDeepSeekDeepSeek
    CoPilotCoPilotStable DiffusionStable DiffusionMidjourneyMidjourney
    View All Directories
    OverviewRulesPromptsMCPsAgentsGamesBlogVideosGuidesCoursesCommunityTrending
    DeepSeekBlogIntroducing DotNetPy: Python Interop for Modern .NET, Reimagined
    Back to Blog
    Introducing DotNetPy: Python Interop for Modern .NET, Reimagined
    dotnet

    Introducing DotNetPy: Python Interop for Modern .NET, Reimagined

    Jung Hyun, Nam March 19, 2026
    0 views

    A lightweight, AOT-compatible library that lets you call Python from C# in 4 lines — with declarative uv integration and compile-time security checks.


    title: "Introducing DotNetPy: Python Interop for Modern .NET, Reimagined" published: true description: "A lightweight, AOT-compatible library that lets you call Python from C# in 4 lines — with declarative uv integration and compile-time security checks." tags: dotnet, python, csharp, opensource cover_image: https://raw.githubusercontent.com/rkttu/dotnetpy/main/dotnetpy.png

    The Problem

    .NET and Python are two of the most widely used platforms in enterprise software today, yet bringing them together has always been painful. Existing interop libraries either require heavy runtime dependencies, lack support for modern .NET features like Native AOT, or demand complex project configurations with Source Generators.

    If you've ever wanted to leverage Python's rich data science and ML ecosystem from a C# application — without leaving your .NET toolchain — you know the friction.

    DotNetPy is my answer to that problem. Version 0.5.0 is now available on NuGet.

    What Is DotNetPy?

    DotNetPy (pronounced dot-net-pie) is a .NET library for executing Python code directly from C#. It wraps the Python C API behind a clean, minimal interface.

    Here's the entire "hello world":

    var executor = Python.GetInstance();
    var temperatures = new[] { 23.5, 19.2, 31.8, 27.4, 22.1 };
    
    using var result = executor.ExecuteAndCapture(@"
        import statistics
        result = {'mean': statistics.mean(data), 'stdev': statistics.stdev(data)}
    ", new Dictionary<string, object?> { { "data", temperatures } });
    
    Console.WriteLine($"Mean: {result?.GetDouble("mean"):F1}°C ± {result?.GetDouble("stdev"):F1}");
    

    No separate .py files. No Source Generators. No complex setup.

    Why Another Interop Library?

    There are established options — pythonnet, CSnakes, IronPython. Each has strengths, but none was designed for where .NET is heading in 2025 and beyond. DotNetPy fills that gap with three design pillars:

    1. Native AOT Support

    DotNetPy is the only .NET-Python interop library that works with PublishAot=true. If you're building self-contained, ahead-of-time compiled applications, DotNetPy won't hold you back. Neither pythonnet nor CSnakes support this today.

    2. File-based App Ready (.NET 10+)

    .NET 10 introduces file-based apps — run a single .cs file with dotnet run script.cs, no project file required. DotNetPy is designed to work in this scenario from day one.

    # No csproj needed
    dotnet run my-analysis.cs
    

    This makes it ideal for scripting, prototyping, and lightweight automation tasks where spinning up a full project is overkill.

    3. Declarative uv Integration

    Managing Python environments from .NET has always been a manual, error-prone process. DotNetPy integrates with uv, the fast Python package manager, so you can declare your entire Python environment in C#:

    using var project = PythonProject.CreateBuilder()
        .WithProjectName("my-analysis")
        .WithPythonVersion(">=3.10")
        .AddDependencies("numpy>=1.24.0", "pandas>=2.0.0")
        .Build();
    
    await project.InitializeAsync();  // Downloads Python, creates venv, installs packages
    
    var executor = project.GetExecutor();
    executor.Execute("import numpy as np; print(np.mean([1,2,3]))");
    

    One call to InitializeAsync() handles Python download, virtual environment creation, and dependency installation. No more "works on my machine" issues.

    How Does It Compare?

    Here's a quick comparison with the existing ecosystem:

    DotNetPypythonnetCSnakesIronPython
    Native AOT✅❌❌❌
    File-based Apps✅❌❌❌
    Source Generator RequiredNoNoYesNo
    uv IntegrationBuilt-inNoneSupportedNone
    Bidirectional CallsC#→PyC#↔PyC#→PyC#↔Py
    Learning CurveVery LowMediumHighLow

    DotNetPy deliberately focuses on the C# → Python direction. If you need Python calling back into .NET objects, pythonnet remains the right choice. DotNetPy is for scenarios where .NET is the host and Python is the tool.

    Built-in Security

    Executing dynamic code always carries risk. DotNetPy ships with a Roslyn analyzer that detects potential code injection at compile time.

    // ❌ The analyzer flags this — user input as code
    executor.Execute(userInput);
    
    // ✅ Safe — user data passed as variables
    executor.Execute(
        "result = sum(numbers)",
        new Dictionary<string, object?> { { "numbers", userNumbers } }
    );
    

    This is a deliberate design choice: make the safe path easy and the dangerous path visible.

    Features at a Glance

    • Automatic Python Discovery — cross-platform detection of installed Python distributions
    • Data Marshaling — pass .NET arrays, dictionaries, and primitives to Python and back
    • Variable Management — capture, check, delete, and clear Python variables from C#
    • Free-threaded Python Support — detects Python 3.13+ builds with --disable-gil
    • Thread Safety — automatic GIL management for safe concurrent access

    Getting Started

    Install from NuGet:

    dotnet add package DotNetPy --version 0.5.0
    

    Initialize and run:

    using DotNetPy;
    
    Python.Initialize("/path/to/python313.dll");
    var executor = Python.GetInstance();
    
    var sum = executor.Evaluate("sum([1,2,3,4,5])")?.GetInt32();
    Console.WriteLine(sum); // 15
    

    Or let DotNetPy find Python automatically:

    Python.Initialize(PythonDiscovery.FindPython());
    

    Use Cases I'm Targeting

    • AI/ML integration: Call scikit-learn, PyTorch, or Hugging Face models from a .NET service
    • Data analysis scripts: Run pandas/numpy workloads inline without a separate Python service
    • Automation & scripting: Use .NET 10 file-based apps as Python-capable scripts
    • Legacy modernization: Gradually introduce Python capabilities into existing .NET applications

    What's Next

    The roadmap includes embeddable Python support on Windows (for simplified deployment) and specialized optimizations for AI and data science workflows. This is v0.5.0 — the API is stabilizing, and feedback at this stage is especially valuable.

    Links

    • GitHub: github.com/rkttu/dotnetpy
    • NuGet: DotNetPy 0.5.0
    • Docs: Usage Examples · Security Guide · Comparison
    • License: Apache 2.0

    If you're a .NET developer who's been eyeing Python's ecosystem, give DotNetPy a try. Issues, stars, and feedback are all welcome.

    Tags

    dotnetpythoncsharpopensource

    Comments

    More Blog

    View all
    Five Gemma-4 models, one accelerator: what porting E2B 31B to AWS Inferentia2 taught megemma

    Five Gemma-4 models, one accelerator: what porting E2B 31B to AWS Inferentia2 taught me

    I ported the whole Gemma-4 family — E2B, E4B, 12B, 31B, and the 26B-A4B MoE — to run on...

    X
    xbill
    Hey DEV, I'm Tobore. Let's actually connect.community

    Hey DEV, I'm Tobore. Let's actually connect.

    Hey DEV, I'm Tobore. Let's actually connect. I've been on here for a while now, mostly writing and...

    L
    Laurina Ayarah
    I burned through thousands of AI tokens. Then a friend did it for freeai

    I burned through thousands of AI tokens. Then a friend did it for free

    (yep, kinda clickbait, just for the funsies 😊) At the beginning of the year, I relaunched my...

    P
    Paulo Henrique
    Claude might be saturating your machineai

    Claude might be saturating your machine

    My laptop was sitting idle with the fan at full tilt. Nothing was running that I knew of. The culprit...

    S
    Sidhant Panda
    Automated GitHub Code Reviews Using Google Geminigithubactions

    Automated GitHub Code Reviews Using Google Gemini

    I Built a Thing! TL;DR — Google Gemini-based Pull Request reviews and Issue Triaging for...

    D
    Darren "Dazbo" Lester
    What is an "agentic harness," actually?ai

    What is an "agentic harness," actually?

    I've been hearing the word "harness" thrown around a lot lately. I assumed it just meant "the IDE" or...

    T
    Tilde A. Thurium

    Stay up to date

    Get the latest DeepSeek prompts, rules, and resources delivered to your inbox weekly.

    Neura Market LogoNeura Market

    Discover the best AI prompts, plugins, and resources for DeepSeek and more.

    Content Types

    • Rules
    • Prompts
    • MCPs
    • Agents
    • Guides

    Platforms

    • ChatGPT Directory
    • Claude Directory
    • Gemini Directory
    • Cursor Directory
    • Grok Directory
    • Perplexity Directory
    • DeepSeek Directory
    • CoPilot Directory
    • Stable Diffusion Directory
    • Midjourney Directory
    • All Directories

    Resources

    • Blog
    • Documentation
    • Help Center
    • Marketplace

    Legal

    • Privacy Policy
    • Terms of Service

    © 2026 Neura Market. All rights reserved.

    |

    Not affiliated with any AI platform vendors.

    Neura Market

    Custom AI Systems & Services

    Our team of experienced AI builders will help build custom AI systems, workflows, and solutions for your business.

    Request custom work

    Ready-made automations for this

    Workflows from the Neura Market marketplace related to this DeepSeek resource

    • Automate Blog Post Publishing from Airtable to Hashnode with API Integrationn8n · $14.99 · Related topic
    • YouTube Video to WordPress Blog Automation with Gemini AI & Affiliate Integrationn8n · $14.99 · Related topic
    • Call Analyzer with AssemblyAI Transcription and OpenAI Assistant Integrationn8n · $14.99 · Related topic
    • Convert Time Zones with TimeZoneDB API Integrationn8n · $4.99 · Related topic
    Browse all workflows