Convert Figma logo to code with AI

IronLanguages logoironpython2

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

1,072
228
1,072
213

Top Related Projects

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

1,202

Python for the Java Platform

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

A Python Interpreter written in Rust

11,701

Nuitka is a Python compiler written in Python. It's fully compatible with Python 2.6, 2.7, 3.4-3.12. You feed it your Python app, it does a lot of clever things, and spits out an executable or extension module.

Quick Overview

IronPython2 is an open-source implementation of the Python programming language that is tightly integrated with the .NET Framework. It allows developers to use Python within .NET applications and leverage the extensive .NET ecosystem while maintaining Python's simplicity and flexibility.

Pros

  • Seamless integration with .NET Framework and its libraries
  • Access to powerful .NET features and performance optimizations
  • Ability to use Python and .NET languages in the same project
  • Cross-language debugging capabilities

Cons

  • Limited to Python 2.7 syntax and features
  • Slower development compared to the main CPython implementation
  • Some Python libraries may not be fully compatible
  • Smaller community and ecosystem compared to standard Python

Code Examples

  1. Importing and using .NET classes:
from System import DateTime

current_time = DateTime.Now
print(f"Current time: {current_time}")
  1. Creating a Windows Forms application:
import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import Application, Form, Label

form = Form()
form.Text = "Hello, IronPython!"
label = Label()
label.Text = "Welcome to IronPython"
form.Controls.Add(label)
Application.Run(form)
  1. Interacting with .NET collections:
from System.Collections.Generic import List

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

for num in numbers:
    print(num)

Getting Started

  1. Install IronPython2:

    pip install ironpython
    
  2. Create a new Python file (e.g., example.py) and add the following code:

    import clr
    clr.AddReference("System")
    from System import Console
    
    Console.WriteLine("Hello from IronPython!")
    
  3. Run the script using the IronPython interpreter:

    ipy example.py
    

This will execute the Python code using IronPython, demonstrating the integration with .NET's Console class.

Competitor Comparisons

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

Pros of ironpython3

  • Supports Python 3 syntax and features
  • More active development and maintenance
  • Better compatibility with modern Python libraries

Cons of ironpython3

  • May have compatibility issues with older Python 2 code
  • Potentially less stable than the more mature ironpython2
  • Some .NET interoperability features might not be fully implemented yet

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 shows some of the syntax differences between Python 2 and Python 3, which are reflected in the respective IronPython implementations. ironpython3 uses the updated print function, range instead of xrange, and input instead of raw_input.

Both projects aim to provide Python implementation for the .NET Framework, but ironpython3 focuses on supporting the more recent Python 3 language features and standard library, while ironpython2 maintains compatibility with Python 2 code and libraries.

1,202

Python for the Java Platform

Pros of Jython

  • Better integration with Java ecosystem and libraries
  • Supports more recent Python versions (up to Python 2.7)
  • Generally faster execution speed for Java-heavy applications

Cons of Jython

  • Limited support for CPython C extensions
  • Slower development cycle and less frequent updates
  • Smaller community and ecosystem compared to IronPython

Code Comparison

Jython:

from java.util import ArrayList

list = ArrayList()
list.add("Hello")
list.add("World")
print(list.get(0) + " " + list.get(1))

IronPython:

from System.Collections.Generic import List[str]

list = List[str]()
list.Add("Hello")
list.Add("World")
print(list[0] + " " + list[1])

Both implementations allow seamless integration with their respective host platforms (Java and .NET). Jython's syntax is closer to standard Python when working with Java classes, while IronPython requires more explicit type declarations for .NET collections.

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

Pros of micropython

  • Designed for microcontrollers and embedded systems, offering a more lightweight implementation
  • Supports a wide range of hardware platforms and boards
  • Actively maintained with frequent updates and improvements

Cons of micropython

  • Limited standard library compared to CPython or IronPython
  • May not be suitable for larger, more complex applications
  • Some Python features and modules are not available due to resource constraints

Code comparison

MicroPython:

import machine
import time

led = machine.Pin(2, machine.Pin.OUT)
while True:
    led.toggle()
    time.sleep(1)

IronPython:

import System.Threading
import System.Console

while True:
    System.Console.WriteLine("Hello from IronPython!")
    System.Threading.Thread.Sleep(1000)

The MicroPython example demonstrates direct hardware control, while the IronPython example shows integration with .NET framework classes. This highlights the different focus areas of the two implementations: MicroPython for embedded systems and IronPython for .NET integration.

A Python Interpreter written in Rust

Pros of RustPython

  • Written in Rust, offering better performance and memory safety
  • More actively maintained with frequent updates
  • Supports a wider range of Python versions, including more recent ones

Cons of RustPython

  • Less mature project compared to IronPython2
  • May have fewer .NET-specific integrations and features
  • Potentially smaller community and 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();
    });
}

IronPython2:

using IronPython.Hosting;

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

Both examples demonstrate how to execute a simple Python script within their respective environments. RustPython uses a more verbose approach with explicit VM creation and compilation, while IronPython2 provides a more straightforward API for executing Python code within .NET.

11,701

Nuitka is a Python compiler written in Python. It's fully compatible with Python 2.6, 2.7, 3.4-3.12. You feed it your Python app, it does a lot of clever things, and spits out an executable or extension module.

Pros of Nuitka

  • Compiles Python code to standalone executables, improving performance
  • Supports a wide range of Python versions and libraries
  • Actively maintained with frequent updates and improvements

Cons of Nuitka

  • Compilation process can be slower compared to IronPython2
  • May have compatibility issues with some Python libraries or frameworks
  • Larger executable size compared to interpreted Python scripts

Code Comparison

IronPython2:

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

Nuitka:

# No special imports needed
print("Hello from Nuitka!")
# Nuitka compiles standard Python code

Summary

Nuitka focuses on compiling Python to native executables, offering performance benefits and cross-platform compatibility. IronPython2 integrates Python with the .NET framework, providing access to .NET libraries. Nuitka is more suitable for standalone Python applications, while IronPython2 excels in .NET environments. Choose based on your specific requirements and target platform.

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 has been released and is now available for download at https://github.com/IronLanguages/ironpython3!

IronPython

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

IronPython can be obtained at http://ironpython.net/.

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

Comparison of IronPython vs. C# for 'Hello World'

C#:

using System;
class Hello
{
    static void Main() 
    {
        Console.WriteLine("Hello World");
    }
}

IronPython:

print "Hello World"

IronPython is a Dynamic Language that runs on the .NET DLR (Dynamic Language Runtime) in contrast with VB.NET and C# which are static languages.

IronPython can also import DLL files compiled in other languages and use functions defined therein. For example:

import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import *

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.

Documentation

Documentation can be found here: http://ironpython.net/documentation/dotnet/

Additional information

Please see http://wiki.github.com/IronLanguages/main for information on:

  • Setting up a development environment with easy access to utility scripts
  • Building
  • Running test

Chat/Communication

Join our Gitter-Chat under: https://gitter.im/IronLanguages/ironpython