Convert Figma logo to code with AI

IronLanguages logoironpython3

Implementation of Python 3.x for .NET Framework that is built on top of the Dynamic Language Runtime.

2,466
286
2,466
285

Top Related Projects

Implementation of the Python programming language for .NET Framework; built on top of the Dynamic Language Runtime (DLR).

1,202

Python for the Java Platform

A Python Interpreter written in Rust

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems

9,764

NumPy aware dynamic Python compiler using LLVM

Quick Overview

IronPython3 is an open-source implementation of the Python programming language for the .NET Framework and Mono. It aims to be fully compatible with Python 3.x while providing seamless integration with .NET libraries and technologies. IronPython3 allows developers to use Python within .NET applications and vice versa.

Pros

  • Seamless integration with .NET Framework and libraries
  • Access to both Python and .NET ecosystems
  • Good performance due to compilation to .NET IL (Intermediate Language)
  • Cross-platform support through .NET Core

Cons

  • May lag behind the latest CPython releases in terms of feature support
  • Some Python libraries with C extensions may not be compatible
  • Smaller community compared to CPython
  • Limited documentation and resources compared to mainstream Python

Code Examples

  1. Basic Python code execution:
import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import MessageBox

MessageBox.Show("Hello from IronPython3!")

This example demonstrates how to use .NET libraries (System.Windows.Forms) within Python code.

  1. Accessing .NET classes:
from System.Collections.Generic import List

numbers = List[int]()
numbers.Add(1)
numbers.Add(2)
numbers.Add(3)

print(numbers.Count)  # Output: 3

This code shows how to use .NET generic collections in IronPython3.

  1. Creating a simple WPF application:
import wpf
from System.Windows import Application, Window

class MyWindow(Window):
    def __init__(self):
        wpf.LoadComponent(self, 'MyWindow.xaml')

if __name__ == '__main__':
    Application().Run(MyWindow())

This example demonstrates how to create a basic WPF application using IronPython3.

Getting Started

To get started with IronPython3:

  1. Install IronPython3:

    pip install ironpython3
    
  2. Create a new Python file (e.g., hello.py) with the following content:

    print("Hello, IronPython3!")
    
  3. Run the script using IronPython3:

    ipy3 hello.py
    

For more advanced usage, including .NET integration, refer to the official documentation and examples in the GitHub repository.

Competitor Comparisons

Implementation of the Python programming language for .NET Framework; built on top of the Dynamic Language Runtime (DLR).

Pros of ironpython2

  • More stable and mature implementation
  • Better compatibility with existing Python 2.x codebases
  • Wider range of available libraries and frameworks

Cons of ironpython2

  • Based on Python 2, which is no longer actively maintained
  • Lacks modern Python 3 features and syntax improvements
  • Limited future support and development

Code Comparison

ironpython2:

print "Hello, World!"
xrange(10)
raw_input("Enter your name: ")

ironpython3:

print("Hello, World!")
range(10)
input("Enter your name: ")

The code comparison highlights some of the syntax differences between Python 2 and Python 3. ironpython3 uses parentheses for print statements, replaces xrange with range, and uses input instead of raw_input.

ironpython3 is the more future-proof option, aligning with the latest Python language standards and receiving ongoing updates. It offers improved Unicode support, better error handling, and access to newer Python libraries. However, ironpython2 may still be necessary for maintaining legacy projects or when working with older dependencies that haven't been updated for Python 3.

Ultimately, the choice between ironpython2 and ironpython3 depends on project requirements, existing codebase compatibility, and long-term maintenance considerations.

1,202

Python for the Java Platform

Pros of Jython

  • Seamless Java integration, allowing direct use of Java libraries and classes
  • Better performance for certain tasks due to JVM optimization
  • More mature and established project with a longer history

Cons of Jython

  • Limited to Python 2.7 compatibility, lacking support for newer Python features
  • Slower development and update cycle compared to IronPython3
  • Less active community and fewer recent contributions

Code Comparison

Jython:

from java.util import ArrayList
list = ArrayList()
list.add("Hello")
list.add("World")
print(list.get(0) + " " + list.get(1))

IronPython3:

from System.Collections.Generic import List[str]
list = List[str]()
list.Add("Hello")
list.Add("World")
print(f"{list[0]} {list[1]}")

Both implementations showcase integration with their respective platforms (Java and .NET). Jython uses Java's ArrayList, while IronPython3 uses .NET's generic List. The syntax differences are minor, with IronPython3 using more Python 3-style features like f-strings.

A Python Interpreter written in Rust

Pros of RustPython

  • Written in Rust, offering better performance and memory safety
  • More actively maintained with frequent updates and contributions
  • Supports a wider range of Python 3 features and standard library modules

Cons of RustPython

  • Less mature project compared to IronPython3
  • May have compatibility issues with some existing Python libraries
  • Lacks integration with .NET ecosystem

Code Comparison

RustPython:

use rustpython_vm as vm;

fn main() {
    vm::Interpreter::without_stdlib(Default::default()).enter(|vm| {
        let code = vm.compile("print('Hello, World!')", "example.py", vm::compiler::Mode::Exec).unwrap();
        vm.run_code_obj(code, vm.new_scope_with_builtins()).unwrap();
    });
}

IronPython3:

using IronPython.Hosting;

class Program
{
    static void Main(string[] args)
    {
        var engine = Python.CreateEngine();
        engine.Execute("print('Hello, World!')");
    }
}

Both implementations aim to provide Python functionality in different environments. RustPython focuses on Rust integration and performance, while IronPython3 leverages the .NET ecosystem. The choice between them depends on specific project requirements and target platforms.

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems

Pros of micropython

  • Designed for microcontrollers and embedded systems, optimized for resource-constrained environments
  • Smaller footprint and faster execution compared to IronPython3
  • Includes hardware-specific modules for direct interaction with microcontroller peripherals

Cons of micropython

  • Limited standard library support compared to IronPython3
  • Less compatible with existing Python codebases and libraries
  • Primarily focused on embedded systems, not as versatile for general-purpose programming

Code Comparison

micropython:

import machine
led = machine.Pin(2, machine.Pin.OUT)
led.on()

IronPython3:

import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import MessageBox
MessageBox.Show("Hello, IronPython!")

The micropython example demonstrates direct hardware interaction, while the IronPython3 example showcases integration with .NET libraries. This highlights the different focus areas of the two projects: micropython for embedded systems and IronPython3 for .NET integration.

9,764

NumPy aware dynamic Python compiler using LLVM

Pros of numba

  • Significantly faster execution for numerical Python code
  • Supports CUDA GPU acceleration for parallel processing
  • Seamless integration with NumPy arrays and functions

Cons of numba

  • Limited to a subset of Python and NumPy features
  • Requires careful attention to supported data types and operations
  • May have compilation overhead for short-running functions

Code comparison

numba:

from numba import jit
import numpy as np

@jit(nopython=True)
def sum_array(arr):
    return np.sum(arr)

ironpython3:

import clr
clr.AddReference("System.Numerics")
from System.Numerics import BigInteger

def sum_array(arr):
    return sum(BigInteger(x) for x in arr)

numba focuses on optimizing numerical computations, while ironpython3 provides Python integration with the .NET ecosystem. numba excels in performance for scientific computing, whereas ironpython3 offers broader interoperability with .NET libraries and frameworks. The choice between them depends on the specific requirements of your project, such as performance needs, target platform, and integration with existing systems.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

IronPython 3

There is still much that needs to be done to support Python 3.x. We are working on it, albeit slowly. We welcome all those who would like to help!

Official Website

IronPython is an open-source implementation of the Python programming language that is tightly integrated with .NET. IronPython can use .NET and Python libraries, and other .NET languages can use Python code just as easily.

IronPython 3 targets Python 3, including the re-organized standard library, Unicode strings, and all of the other new features.

What?Where?
Windows/Linux/macOS BuildsBuild status Github build status
DownloadsNuGet Release
HelpGitter chat StackExchange

Examples

The following C# program:

using System.Windows.Forms;

MessageBox.Show("Hello World!", "Greetings", MessageBoxButtons.OKCancel);

can be written in IronPython as follows:

import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import MessageBox, MessageBoxButtons

MessageBox.Show("Hello World!", "Greetings", MessageBoxButtons.OKCancel)

Here is an example how to call Python code from a C# program.

var eng = IronPython.Hosting.Python.CreateEngine();
var scope = eng.CreateScope();
eng.Execute(@"
def greetings(name):
    return 'Hello ' + name.title() + '!'
", scope);
dynamic greetings = scope.GetVariable("greetings");
System.Console.WriteLine(greetings("world"));

This example assumes that IronPython has been added to the C# project as a NuGet package.

Code of Conduct

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information see the .NET Foundation Code of Conduct.

State of the Project

The current target is Python 3.4, although features and behaviors from later versions may be included.

See the following lists for features from each version of CPython that have been implemented:

Contributing

For details on contributing see the Contributing article.

Upgrading from IronPython 2

For details on upgrading from IronPython 2 to 3 see the Upgrading from IronPython 2 to 3 article.

Differences with CPython

While compatibility with CPython is one of our main goals with IronPython 3, there are still some differences that may cause issues. See Differences from CPython for details.

Package compatibility

See the Package compatibility document for information on compatibility with popular packages.

Installation

Binaries of IronPython 3 can be downloaded from the release page, available in various formats: .msi, .zip, .deb, .pkg. The IronPython package is also available on NuGet. See the installation document for detailed instructions on how to install a standalone IronPython interpreter on various operating systems and .NET frameworks.

Build

See the building document. Since the main development is on Windows, bugs on other platforms may inadvertently be introduced - please report them!

Supported Platforms

IronPython 3 targets .NET Framework 4.6.2, .NET Standard 2.0 and .NET 6.0. The support for .NET and .NET Core follow the lifecycle defined on .NET and .NET Core Support Policy.