Recent from talks
Contribute something
Nothing was collected or created yet.
IronPython
View on Wikipedia| IronPython | |
|---|---|
| Original authors | Jim Hugunin, Microsoft |
| Developers | Dino Viehland, .NET Foundation |
| Initial release | September 5, 2006[1] |
| Stable release | 3.4.2
/ December 20, 2024 |
| Preview release | 3.4.0-beta1
/ April 30, 2022 |
| Repository | |
| Written in | C# |
| Operating system | Windows, Linux, macOS |
| Platform | .NET Framework, .NET, Mono |
| Type | Python programming language implementation |
| License | Apache License 2.0 |
| Website | ironpython |
IronPython is an implementation of the Python programming language targeting the .NET and Mono frameworks. The project is currently maintained by a group of volunteers at GitHub. It is free and open-source software, and can be implemented with Python Tools for Visual Studio, which is a free and open-source extension for Microsoft's Visual Studio IDE.[2][3]
IronPython is written entirely in C#, although some of its code is automatically generated by a code generator written in Python.
IronPython is implemented on top of the Dynamic Language Runtime (DLR), a library running on top of the Common Language Infrastructure that provides dynamic typing and dynamic method dispatch, among other things, for dynamic languages.[4] The DLR is part of the .NET Framework 4.0 and is also a part of Mono since version 2.4 from 2009.[5] The DLR can also be used as a library on older CLI implementations.
Status and roadmap
[edit]Jim Hugunin created the project and actively contributed to it up until Version 1.0 which was released on September 5, 2006.[6] IronPython 2.0 was released on December 10, 2008.[7] After version 1.0 it was maintained by a small team at Microsoft until the 2.7 Beta 1 release. Microsoft abandoned IronPython (and its sister project IronRuby) in late 2010, after which Hugunin left to work at Google.[8] The project is currently maintained by a group of volunteers at GitHub.
- Release 2.0, released on December 10, 2008, and updated as 2.0.3 on October 23, 2009, targets CPython 2.5.[9] IronPython 2.0.3 is only compatible up to .NET Framework 3.5.
- Release 2.6, released on December 11, 2009, and updated on April 12, 2010, targets CPython 2.6.[10] IronPython 2.6.1 versions is binary compatible only with .NET Framework 4.0. IronPython 2.6.1 must be compiled from sources to run on .NET Framework 3.5. IronPython 2.6.2, released on October 21, 2010, is binary compatible with both .NET Framework 4.0 and .NET Framework 3.5.
- Release 2.7 was released on March 12, 2011 and it targets CPython 2.7.[11]
- Release 2.7.1 was released on October 21, 2011 and it targets CPython 2.7.[12]
- Release 2.7.2.1 was released on March 13, 2012. It enables support for ZIP file format libraries, SQLite, and compiled executables.[13]
- Release 2.7.4 was released on September 7, 2013.[14]
- Release 2.7.5 was released on December 6, 2014 and mostly consists of bug fixes.[15]
- Release 2.7.6 was released on August 21, 2016 and only consists of bug fixes.[16]
- Release 2.7.7 was released on December 7, 2016 and only consists of bug fixes.[17]
- Release 2.7.8 was released on February 16, 2018 and consists of bug fixes, reorganized code, and an updated test infrastructure (including significant testing on Linux under Mono). It is also the first release to support .NET Core.[18]
- Release 2.7.9 was released on October 9, 2018 and consists of bug fixes, reorganized code. It is intended to be the last release before IronPython 3.[19]
- Release 2.7.10 was released on April 27, 2020 and adds .NET Core 3.1 support.[20]
- Release 2.7.11 was released on November 17, 2020 and resolves issues when running on .NET 5.
- Release 2.7.12 was released on January 21, 2022 and resolves issues with .NET 6 and removes support for .NET core 2.1[21]
- Release 3.4.0 was released on December 12, 2022 and is the first release to support Python 3.x. [22]
Differences with CPython
[edit]This section needs expansion. You can help by adding missing information. (July 2012) |
There are some differences between the Python reference implementation CPython and IronPython.[23] Some projects built on top of IronPython are known not to work under CPython.[24] Conversely, CPython applications that depend on extensions to the language that are implemented in C are not compatible with IronPython ,[25] unless they are implemented in a .NET interop. For example, NumPy was wrapped by Microsoft in 2011, allowing code and libraries dependent on it to be run directly from .NET Framework.[26]
Silverlight
[edit]IronPython is supported on Silverlight (which is deprecated by Microsoft and already has lost support in most web browsers[27]). It can be used as a scripting engine in the browser just like the JavaScript engine.[28] IronPython scripts are passed like simple client-side JavaScript scripts in <script>-tags. It is then also possible to modify embedded XAML markup.
The technology behind this is called Gestalt.[citation needed]
<!-- DLR initialization script. -->
<script src="http://gestalt.ironpython.net/dlr-latest.js" type="text/javascript"></script>
<!-- Client-side script passed to IronPython and Silverlight. -->
<script type="text/python">
window.Alert("Hello from Python")
</script>
The same works for IronRuby.
License
[edit]Until version 0.6, IronPython was released under the terms of Common Public License.[29] Following recruitment of the project lead in August 2004, IronPython was made available as part of Microsoft's Shared Source initiative. This license is not OSI-approved but the authors claim it meets the open-source definition.[30] With the 2.0 alpha release, the license was changed to the Microsoft Public License,[31] which the OSI has approved. The latest versions are released under the terms of the Apache License 2.0.
Interface extensibility
[edit]One of IronPython's key advantages is in its function as an extensibility layer to application frameworks written in a .NET language. It is relatively simple to integrate an IronPython interpreter into an existing .NET application framework. Once in place, downstream developers can use scripts written in IronPython that interact with .NET objects in the framework, thereby extending the functionality in the framework's interface, without having to change any of the framework's code base.[32]
IronPython makes extensive use of reflection. When passed in a reference to a .NET object, it will automatically import the types and methods available to that object. This results in a highly intuitive experience when working with .NET objects from within an IronPython script.
Examples
[edit]The following IronPython script manipulates .NET Framework objects. This script can be supplied by a third-party client-side application developer and passed into the server-side framework through an interface. Note that neither the interface, nor the server-side code is modified to support the analytics required by the client application.
from BookService import BookDictionary
booksWrittenByBookerPrizeWinners = [book.Title for book in BookDictionary.GetAllBooks()
if "Booker Prize" in book.Author.MajorAwards]
In this case, assume that the .NET Framework implements a class, BookDictionary, in a module called BookService, and publishes an interface into which IronPython scripts can be sent and executed.
This script, when sent to that interface, will iterate over the entire list of books maintained by the framework, and pick out those written by Booker Prize-winning authors.
What's interesting is that the responsibility for writing the actual analytics reside with the client-side developer. The demands on the server-side developer are minimal, essentially just providing access to the data maintained by the server. This design pattern greatly simplifies the deployment and maintenance of complex application frameworks.
The following script uses the .NET Framework to create a simple Hello World message.
import clr
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import MessageBox
MessageBox.Show("Hello World")
Performance
[edit]The performance characteristics of IronPython compared to CPython, the reference implementation of Python, depends on the exact benchmark used. IronPython performs worse than CPython on most benchmarks taken with the PyStone script but better on other benchmarks.[33] IronPython may perform better in Python programs that use threads or multiple cores, as it has a JIT compiler, and also because it doesn't have the Global Interpreter Lock.[34][35]
Overview and key features
[edit]- Integration with .NET: IronPython allows you to use .NET libraries and frameworks directly in your Python code. This means you can leverage the extensive .NET ecosystem and access features that are specific to .NET environments.
- Dynamic Language Runtime (DLR): IronPython runs on the Dynamic Language Runtime, which is a set of services that support dynamic typing and dynamic method invocation in .NET languages.
- Interoperability: You can call .NET code from IronPython and vice versa. This makes it possible to integrate Python scripts with existing .NET applications or use .NET components within Python projects.
- Syntax and Semantics: IronPython aims to be as close as possible to the standard Python language (CPython), though there might be minor differences due to the underlying .NET platform.
- Performance: While IronPython provides good performance for many applications, it might not be as fast as CPython for some tasks, particularly those that rely heavily on Python's native libraries.
- Compatibility: IronPython is compatible with Python 2.x, but it does not support Python 3.x features. This means that some newer Python libraries or syntax may not be available.
See also
[edit]- Boo – a language for the .NET Framework and Mono with Python-inspired syntax and features borrowed from C# and Ruby
- Cobra
- IronScheme
- Jython – an implementation of Python for the Java Virtual Machine
- Cython
- PyPy – a self-hosting interpreter for the Python programming language
- Tao Framework
- Unladen Swallow – A (now-defunct) branch of CPython that aimed to provide superior performance using an LLVM-based just-in-time compiler
References
[edit]- ^ "CodePlex Archive". Archived from the original on 2017-12-26. Retrieved 2014-05-30.
- ^ "IronPython.net". Retrieved 2013-07-03.
- ^ "Python Tools for Visual Studio- Home". Python Tools for Visual Studio. Archived from the original on 2018-01-26. Retrieved 2013-07-03.
- ^ "Dynamic Language Runtime Overview". Microsoft. Retrieved 2014-04-01.
- ^ "2009-07-02 Marek Safar · mono/Mono@340222f". GitHub.
- ^ "Jim Hugunin's blog: IronPython 1.0 released today!". 2006-09-05. Retrieved 2006-12-14.
- ^ "Release dates for ironpython". 2008-12-10. Retrieved 2009-01-25.
- ^ Clarke, Gavin (2010-10-22). "Microsoft cuts loose Iron languages". The Register. Retrieved 2012-04-05.
- ^ "2.0.3". ironpython.codeplex.com. Archived from the original on 2017-12-26. Retrieved 2010-10-16.
- ^ "2.6". ironpython.codeplex.com. Archived from the original on 2018-01-13. Retrieved 2010-10-16.
- ^ "2.7". ironpython.codeplex.com. Archived from the original on 2018-01-02. Retrieved 2011-03-12.
- ^ "2.7.1". ironpython.codeplex.com. Archived from the original on 2017-12-26. Retrieved 2011-12-30.
- ^ "2.7.2.1". ironpython.codeplex.com. Archived from the original on 2017-12-26. Retrieved 2012-03-24.
- ^ "2.7.4". ironpython.codeplex.com. Archived from the original on 2018-01-16. Retrieved 2014-12-07.
- ^ "2.7.5". ironpython.codeplex.com. Archived from the original on 2018-01-26. Retrieved 2014-12-07.
- ^ "2.7.6". github.com. Retrieved 2016-08-21.
- ^ "2.7.7". github.com. Retrieved 2018-01-05.
- ^ "2.7.8". github.com. Retrieved 2018-01-05.
- ^ "2.7.9". github.com. Retrieved 2018-10-09.
- ^ "IronLanguages/ironpython2". GitHub. Retrieved 2020-06-26.
- ^ "Releases · IronLanguages/ironpython2". GitHub. Retrieved 2022-08-08.
- ^ "Releases · IronLanguages/ironpython3". GitHub. Retrieved 2023-07-09.
- ^ "Differences between IronPython 1.0 and CPython 2.4.3". Microsoft. 2007-12-18. Retrieved 2008-02-09.
- ^ Foord, Michael. "New Project: Implementing .NET Libraries in Pure Python". Archived from the original on 2008-08-30. Retrieved 2008-02-09.
- ^ Eby, Phillip (15 October 2005). "Children of a Lesser Python". Retrieved 2008-07-09.
- ^ "NumPy and SciPy for .NET". Retrieved 2019-04-05.
- ^ "Silverlight 5 System Requirements". www.microsoft.com. Retrieved 2019-11-16.
- ^ "Write browser applications in Python". IronPython.net. Archived from the original on 2013-03-17.
- ^ "Original IronPython homepage". 2004-07-28. Archived from the original on February 23, 2010. Retrieved 2007-05-13.
- ^ "Shared Source License for IronPython". 2006-04-28. Retrieved 2007-05-13.
- ^ "Microsoft permissive license". 2007-04-28. Retrieved 2007-05-13.
- ^ "Using .NET objects from IronPython in Resolver One". Archived from the original on 2009-01-14. Retrieved 2008-11-18.
- ^ "IronPython Performance Report". Archived from the original on January 19, 2013. Retrieved 2009-10-05.
- ^ "IronPython at python.org". python.org. Retrieved 2011-04-04.
IronPython has no GIL and multi-threaded code can use multi core processors.
- ^ "Python's Hardest Problem, Revisited". Archived from the original on 2015-10-31. Retrieved 2015-07-15.
External links
[edit]IronPython
View on GrokipediaOverview
Definition and Purpose
IronPython is an open-source implementation of the Python programming language designed specifically for the .NET ecosystem. It provides a tightly integrated environment where Python code can natively access and utilize .NET libraries, while also allowing .NET applications to incorporate Python scripts and modules. As of December 2024, the latest IronPython release (3.4.2) targets Python 3.4, with a parallel branch supporting Python 2.7 (latest 2.7.12 from January 2022); compatibility includes .NET Framework 4.6.2, .NET Standard 2.0, .NET Core, .NET 6.0, .NET 8.0, .NET 9.0, and Mono, enabling seamless execution of supported Python code within diverse .NET platforms.[1][2][4] The primary purpose of IronPython is to bridge the gap between Python's dynamic, interpretive nature and .NET's robust, statically typed framework, facilitating hybrid development in enterprise settings. This integration supports rapid prototyping, automation scripting, and the creation of mixed-language applications where Python's flexibility enhances .NET's performance and library ecosystem, such as leveraging extensive .NET APIs for data processing or UI development without requiring language-specific wrappers.[1][2] IronPython was initially released on September 5, 2006, by developer Jim Hugunin, marking the first stable version of this .NET-targeted Python implementation.[5] At a high level, IronPython's architecture leverages the Dynamic Language Runtime (DLR), a set of services built atop the Common Language Runtime (CLR) to host dynamic languages efficiently. The DLR enables features like dynamic type systems, expression trees for code generation, and optimized method dispatching, allowing IronPython to compile Python abstract syntax trees into intermediate language code that runs on the CLR while maintaining Python's semantic behaviors.[6][1]Key Features
IronPython provides seamless access to .NET libraries, allowing Python scripts to import and utilize .NET assemblies directly through mechanisms such as theclr module and AddReference function, enabling developers to leverage the extensive .NET ecosystem without additional wrappers or bindings.[3] This integration facilitates the use of .NET classes, methods, and events within Python code, promoting interoperability between Python and languages like C# or VB.NET.
Unlike CPython, IronPython operates without a Global Interpreter Lock (GIL), inheriting the .NET Common Language Runtime's (CLR) robust multi-threading capabilities, which allows multiple Python threads to execute concurrently and fully utilize multi-core processors.[7] This absence of the GIL enhances performance in threaded applications, making IronPython particularly advantageous for concurrent programming tasks on .NET platforms.
IronPython 3.x fully supports Python 3 syntax and a subset of the standard library, incorporating .NET-specific extensions that extend functionality, such as improved handling of Unicode strings. It maintains compatibility with many third-party Python packages while augmenting them with .NET equivalents where beneficial.
The implementation is cross-platform, running on Windows, Linux, and macOS through support for .NET Core and .NET 6 or later, ensuring broad deployment flexibility across operating systems without sacrificing .NET integration.[2]
IronPython preserves Python's dynamic typing model, including duck typing, by mapping it onto the .NET type system via the Dynamic Language Runtime (DLR), which enables flexible, late-bound operations while ensuring compatibility with statically typed .NET components.[1]
History
Origins and Early Development
IronPython was initiated by Jim Hugunin, the creator of Jython—a Python implementation for the Java Virtual Machine—in 2003 as a personal prototype to evaluate the .NET Common Language Runtime (CLR) as a platform for dynamic languages.[8] Hugunin, then an independent developer, aimed to demonstrate the CLR's shortcomings for such languages but discovered unexpected potential during the prototyping phase, shifting his focus toward building a viable Python runtime on .NET.[9] This early work was inspired by preliminary explorations of dynamic code generation and binding mechanisms that would later influence the Dynamic Language Runtime (DLR).[8] The primary goals of this initial development were to enable seamless Python execution within .NET environments, facilitating better integration with Windows-specific tools, enterprise software, and the broader .NET ecosystem, where CPython's C-based extensions often posed compatibility challenges.[10] By targeting the CLR, IronPython sought to address these limitations, allowing Python developers to leverage .NET libraries directly without bridging overhead, while providing a managed runtime that could benefit from .NET's garbage collection and security features.[11] Hugunin's experience with Jython informed the design, emphasizing compatibility with core Python semantics alongside .NET interoperability from the outset.[8] The project gained momentum after Hugunin joined Microsoft in 2004, but its foundational prototypes remained independent efforts until formal sponsorship. The first public release, IronPython 1.0, occurred on September 5, 2006, implementing the core features of Python 2.5 and marking a stable milestone for early adopters in .NET-heavy development contexts.[11] This version supported an interactive console, dynamic compilation, and access to .NET assemblies, laying the groundwork for broader adoption prior to deeper corporate integration.[12]Microsoft Involvement
In 2004, Microsoft hired Jim Hugunin, the original creator of IronPython, to enhance the .NET Framework's support for dynamic languages, and the project was integrated into Microsoft's Dynamic Language Runtime (DLR) team.[13] This acquisition marked the beginning of official Microsoft stewardship, with IronPython serving as a key testbed for DLR features like dynamic typing and expression trees.[6] Under this team, development accelerated, focusing on tighter integration with .NET tools and libraries. Microsoft's involvement led to several major releases, including IronPython 2.0 in December 2008, which achieved full compatibility with Python 2.6 and introduced seamless integration with Visual Studio for editing, debugging, and project management.[14][15] Subsequent versions, such as 2.6 in December 2009 and 2.7 in April 2011, further aligned IronPython with CPython's 2.x series, enhancing standard library support and performance optimizations via the DLR.[16] During this period, IronPython also enabled Python scripting in Silverlight applications, allowing dynamic content creation in browser-based .NET environments from 2007 onward.[17] Microsoft's peak contributions culminated in these 2.6 and 2.7 releases, which represented the height of official investment in interoperability and tooling. However, in October 2010, Microsoft ceased active development, transitioning the project to open-source under the Apache License 2.0 and handing maintenance to the community.[10] This shift ended Microsoft's direct role, though the foundational work during this era solidified IronPython's position within the .NET ecosystem.[13]Post-Microsoft Era
Following Microsoft's decision to end active development in October 2010, IronPython transitioned to an independent open-source project relicensed under the Apache 2.0 license, allowing community stewardship.[8] The codebase was subsequently hosted on GitHub under the IronLanguages organization, with repositories established between 2011 and 2012 to facilitate collaborative development.[18] This shift marked the beginning of volunteer-led maintenance, focusing on preserving .NET integration while addressing evolving Python standards. A key community achievement was the addition of compatibility with the cross-platform .NET Core runtime, initially introduced in IronPython 2.7.8 released in February 2018, and expanded in subsequent versions like 2.7.10 in April 2020, 2.7.11 in November 2020, and 2.7.12 in January 2022 to support .NET Core 3.1, .NET Standard, and later .NET versions.[19] This migration enabled IronPython to run on non-Windows platforms, broadening its applicability beyond the traditional .NET Framework. Efforts toward Python 3 compatibility culminated in the project's first stable 3.x release, IronPython 3.4.0, on December 12, 2022, targeting Python 3.4 semantics with support for .NET Framework 4.6.2, .NET Core 3.1, and .NET 6. Subsequent updates included 3.4.1 in July 2023 and 3.4.2 in December 2024, incorporating bug fixes and enhanced library compatibility.[20] As of 2025, IronPython's development remains volunteer-driven through GitHub pull requests and issues, with contributions emphasizing incremental improvements and compatibility enhancements despite a modest pace.Current Status and Roadmap
Maintenance and Community
IronPython's development is governed as an open-source project under the Apache 2.0 license, maintained by a core team of contributors through the IronLanguages organization.[1] The primary repositories are hosted on GitHub at IronLanguages/ironpython3 for the Python 3.x implementation and IronLanguages/ironpython2 for the Python 2.x branch, where code, documentation, and release artifacts are managed collaboratively.[2][18] Releases are distributed via multiple channels, including NuGet packages for easy integration into .NET projects, MSI installers for Windows (primarily for the 2.x series), and ZIP archives available directly from GitHub.[21][22] The project maintains a slow but steady pace of activity, with the latest stable release, IronPython 3.4.2, issued on December 19, 2024, targeting .NET Framework 4.6.2, .NET Standard 2.0, .NET 6.0, .NET 8.0, and compatible with .NET 9.[23] In 2025, development has continued with occasional commits addressing bug fixes and minor enhancements, alongside resolutions to select open issues, reflecting ongoing but limited maintenance efforts.[24] This measured activity stems from the project's transition to community-driven stewardship following its open-sourcing by Microsoft in 2010.[1] The IronPython community remains small yet dedicated, comprising developers interested in .NET-Python interoperability, with contributions welcomed for bug reports, fixes, and feature proposals via GitHub pull requests.[2] Discussions and support occur primarily through informal channels, including the [ironpython] tag on Stack Overflow for technical questions, threads in subreddits like r/dotnet, and the project's Gitter chat room for real-time collaboration.[25][26][27] The official website, ironpython.net, serves as a central hub for announcements, downloads, and documentation, though it does not host dedicated forums.[1] Support for IronPython relies on community self-help, with GitHub issues serving as the main venue for reporting and tracking bugs, particularly challenges related to non-Windows platforms like Linux and macOS compatibility.[28] There is no formal paid support structure, emphasizing the project's volunteer-led nature and encouraging users to engage directly with the contributor base for assistance.[1]Development Targets and Future Plans
IronPython's primary development target remains full compliance with the Python 3.4 standard library, including its reorganized structure, Unicode strings, and core semantics, while selectively incorporating features and behaviors from later Python 3.x versions to enhance compatibility where possible.[2] This approach ensures that most Python 3.4 syntax and modules function as expected, though full equivalence with CPython is not guaranteed due to underlying .NET integration.[29] Alignment with the .NET ecosystem is a key focus, with ongoing support for .NET Framework 4.6.2, .NET Standard 2.0, .NET 6.0, .NET 8.0, and compatibility with .NET 9, extending to future .NET versions to maintain interoperability in modern development environments.[2] Efforts emphasize cross-platform stability, enabling deployment on Windows, Linux, and macOS, although non-Windows platforms may encounter occasional bugs stemming from the project's historical Windows-centric testing.[2] As of 2025, no formal long-term roadmap has been published for IronPython, with development priorities centered on bug fixes, operational parity across supported operating systems, and incremental enhancements potentially drawing from Python 3.5 and subsequent releases.[2] Progress is entirely volunteer-dependent, contributing to a measured pace of updates that limits comprehensive adoption of advanced features from Python 3.12 and later.[2] The project's challenges are primarily resource-related, as a small community of contributors handles maintenance amid competing priorities, resulting in partial or absent support for certain later Python 3.x elements, such as full async/await integration, and incomplete coverage of the evolving Python ecosystem beyond 3.4 baselines.[2][30]Technical Architecture
Dynamic Language Runtime
The Dynamic Language Runtime (DLR) is a runtime environment developed by Microsoft that extends the Common Language Runtime (CLR) of the .NET Framework to support dynamic languages, providing services such as expression trees, call site caching, and dynamic binding for seamless integration with .NET components.[31] Expression trees represent code as data structures that capture language semantics, including control flow and assignments, while call site caching optimizes repeated dynamic operations by storing type information and operation details for faster subsequent executions.[31] The DLR's binding mechanisms encapsulate language-specific rules, enabling interoperability between dynamic languages and statically typed .NET libraries.[31] In IronPython, the DLR serves as the foundational host for the Python parser, compiler, and executor, transforming Python abstract syntax trees (ASTs) into DLR-compatible expressions for execution on the CLR.[6] It facilitates late binding and dynamic method resolution through dynamic sites, which perform runtime lookups and cache results based on object types, such as generating specialized sites likeDoOperation-Add-0 for efficient arithmetic operations.[6] This architecture allows IronPython to leverage the CLR's just-in-time (JIT) compilation for optimized performance on repeated code paths.[6]
Key components of the DLR in IronPython include binders that map .NET types to Python semantics, ensuring transparent access to .NET assemblies during execution.[6] Additionally, much of IronPython's standard library is implemented in C# rather than Python, compiling to intermediate language (IL) for native .NET performance and direct utilization of the Base Class Library (BCL).[15] For instance, the re module for regular expressions is built in C# using System.Text.RegularExpressions.[32]
IronPython has been built on the DLR since its early development in 2007, aligning with the runtime's initial release to enhance dynamic language support on .NET.[6] Subsequent updates have extended compatibility to .NET Core and .NET Standard, with IronPython 2.7.10 introducing support in 2020 and later versions like 3.4.2 targeting .NET 6.0 and .NET 8.0 for modern cross-platform deployment.[1][2]
Python Compatibility Layers
IronPython achieves compatibility with CPython by reimplementing key components of the Python standard library in C#, allowing Python code to run with minimal modifications while integrating seamlessly with the .NET ecosystem. Core modules such as those for file I/O (e.g., using System.IO equivalents) and threading (e.g., leveraging System.Threading) are ported to utilize .NET primitives, ensuring that standard Python operations map to efficient underlying platform capabilities. This approach covers essential functionality from the Python 3.4 standard library, enabling portability for pure Python scripts without native extensions.[2][15] The implementation provides full support for the syntax and semantics of Python 3.4, including advanced language features like list and dictionary comprehensions, function and class decorators, and metaclasses for customizing class creation. IronPython's parser generates an abstract syntax tree (AST) that adheres to Python 3.4 grammar rules, preserving behaviors such as exception handling, context managers, and generator expressions as defined in the language specification. This fidelity allows developers to write idiomatic Python code that executes identically to CPython in supported scenarios.[20][6] At the core of this compatibility is a custom object model that maps Python types and behaviors to .NET constructs via the Dynamic Language Runtime (DLR). Python objects, such as dynamic instances with arbitrary attributes, are represented using DLR's expression trees and dynamic sites, which handle attribute access, method calls, and operator overloading at runtime. For instance, dynamic attribute assignment in Python is emulated through DLR's binding mechanisms, caching type-specific operations for performance while maintaining Python's loose typing semantics. This mapping ensures that Python's introspection capabilities, like dict and getattr, function as expected.[6] IronPython's version alignment is fixed to Python 3.4 features, incorporating the reorganized standard library, Unicode strings by default, and all stable syntax elements up to that release, but excluding experimental or post-3.4 additions like async/await keywords or f-strings. This deliberate scoping prioritizes stability and full conformance to a specific Python version, facilitating reliable code portability within that boundary.[2]Differences from CPython
Extension and Library Compatibility
IronPython, implemented on the .NET runtime via the Dynamic Language Runtime (DLR), is fundamentally incompatible with CPython extensions that rely on the CPython C API, as it lacks direct support for C-level interfaces like those used in modules such as NumPy and SciPy.[32] This incompatibility arises because IronPython does not embed the CPython interpreter or expose the same C API, preventing seamless loading of compiled extensions designed for CPython.[33] As a result, scientific computing libraries like NumPy, SciPy, and pandas, which depend heavily on C extensions for performance, cannot be used directly and often require full rewrites in .NET languages or alternative implementations.[34][35] Pure Python libraries, lacking C dependencies, generally integrate well with IronPython, provided they avoid constructs like ctypes for calling external C libraries, which may encounter loading issues due to .NET's managed environment.[32] For instance, the requests library can function in older versions compatible with Python 2.7, but newer releases face challenges from dependencies like urllib3 or six that assume CPython-specific behaviors.[36] IronPython's standard library support aligns closely with CPython 2.7 (for IronPython 2.x) and 3.4 (for IronPython 3.x, latest 3.4.2 as of December 2024) for pure Python components, enabling use in scripting and web tasks where such modules predominate.[37] To address these limitations, developers can employ workarounds such as the Ironclad library, a community project that provides a partial CPython API compatibility layer, allowing transparent import of select compiled extensions by emulating the necessary interfaces on .NET.[33] Alternatively, IronPython's built-inclr module facilitates access to .NET equivalents, such as using System.Data for data manipulation in place of pandas or Math.NET Numerics as a substitute for NumPy functionality.[38] Experimental integrations via Python.NET have also enabled limited C extension access by embedding CPython wrappers, though these remain non-standard and require careful configuration.[39]
These compatibility constraints particularly impact domains like scientific computing and machine learning, where C-accelerated libraries are essential, limiting IronPython's adoption there in favor of environments dominated by pure Python code, such as automation scripts or web prototyping.[40][41]
Behavioral and Performance Divergences
IronPython diverges from CPython in its threading model due to the absence of a Global Interpreter Lock (GIL), allowing true parallel execution of Python threads across multiple CPU cores without the serialization imposed by CPython's GIL.[42] This leads to different outcomes in multi-threaded applications, where CPython threads are limited to concurrent execution but not parallelism for CPU-bound tasks, whereas IronPython can achieve actual parallelism, potentially altering program behavior in scenarios involving shared mutable state or race conditions.[43] For instance, CPU-intensive threaded computations in IronPython may complete faster and with less contention, though this requires careful synchronization to avoid unexpected interactions not present in CPython.[44] Integer handling in IronPython leverages the .NET runtime's arbitrary-precision integers, implemented via System.Numerics.BigInteger, contrasting with CPython's native long type that also supports arbitrary precision but uses a distinct internal representation optimized for the C-based interpreter.[38] This integration means IronPython integers seamlessly interoperate with .NET libraries expecting BigInteger, but may exhibit subtle behavioral differences in overflow handling or performance for very large values compared to CPython's approach, where integers transition from fixed-width int to long without explicit type boundaries in Python 3. Such divergences can affect numerical computations involving extensive arithmetic, though both implementations maintain Python's semantic guarantee of unlimited integer size. Exception handling in IronPython aligns closely with .NET's exception model to facilitate interoperation, creating paired Python and .NET exception objects when errors occur across language boundaries, which can alter propagation compared to CPython's purely Python-centric mechanism.[38] In mixed Python-.NET code, an unhandled .NET exception may raise a corresponding Python Exception subclass, potentially bypassing CPython-style finally blocks or context managers in edge cases, leading to different stack trace reporting or cleanup behavior. This design enhances seamless integration but requires developers to account for .NET-specific exception hierarchies when porting CPython code. Other behavioral differences include string handling: IronPython uses UTF-16 encoding forstr (unlike CPython's UTF-32 in Python 3), resulting in surrogate pairs for characters > U+FFFF (length 2 in IronPython vs. 1 in CPython) and different encoding of invalid surrogate pairs.[29] Codec behaviors vary, such as single-byte codecs (e.g., Windows-1252) using "best fit" mappings in IronPython while treating unused positions as invalid in CPython, and UTF-7 always terminating Base64 blocks with '-' in IronPython (optional in CPython). OS interactions differ in environment variable handling, with IronPython using 'replace' error mode (replacing invalid bytes with U+FFFD) instead of CPython's 'surrogateescape'. Recursion defaults to throwing a .NET StackOverflowException, though a limit can be set via command-line options like ipy -X MaxRecursion=100.[29]
IronPython also lacks full support for Unix-style signal handling in the signal module, as the .NET runtime does not expose equivalent POSIX signals, limiting CPython-compatible use for interrupts or alarms in cross-platform scripts.[45]
Performance characteristics of IronPython stem from its reliance on the .NET Just-In-Time (JIT) compiler, resulting in slower startup times due to initial runtime loading and code compilation overhead, unlike CPython's immediate bytecode interpretation.[46] However, once running, IronPython often outperforms CPython in loops or operations invoking .NET methods, as these calls avoid marshalling overhead and benefit from JIT optimizations tailored to the host platform.[47]
Edge cases highlight further divergences, such as floating-point precision, where IronPython adheres strictly to .NET's IEEE 754 double-precision format, which may yield minor representational differences from CPython's C double implementation on certain platforms due to compiler variances.[48]
.NET Integration
Interoperability Mechanisms
IronPython facilitates seamless interaction between Python code and .NET components through the Common Language Runtime (CLR), enabling Python scripts to leverage the full breadth of .NET libraries and frameworks. The primary entry point for this interoperability is theclr module, which provides essential functions for loading .NET assemblies and bridging the two environments.[3]
To import .NET assemblies, developers first execute import clr to access the CLR integration layer. Core assemblies such as mscorlib and System are pre-loaded automatically, allowing immediate use without additional steps. For other assemblies, the clr.AddReference function dynamically loads them by name or file path, such as clr.AddReference('System.Xml') for XML processing capabilities or clr.AddReference('assembly.dll') for custom DLLs. This process exposes the assembly's contents as Python-accessible modules, integrating .NET metadata directly into the Python namespace.[3][15]
Accessing .NET types from IronPython involves importing namespaces and classes as Python modules and objects, treating them as native Python entities while retaining .NET behaviors. For instance, after loading the System assembly, Python code can instantiate classes like Console via from [System](/page/System) import Console, followed by method calls such as Console.WriteLine('Hello') to output text to the console. This syntax supports inheritance, polymorphism, and static members, allowing Python to subclass .NET types and override methods transparently.[3][15]
Data marshalling in IronPython occurs automatically during interactions, converting between Python and .NET types to minimize developer overhead. Python lists map to .NET IEnumerable or arrays, strings to System.String, integers to System.Int32, and dictionaries to IDictionary, with bidirectional support for return values. More complex types, like Python tuples, convert to .NET tuples or object arrays, while .NET enums and value types integrate as Python equivalents. This conversion layer, powered by the Dynamic Language Runtime (DLR), ensures type safety and performance without explicit casting in most cases.[15]
Calling conventions enable bidirectional execution, where Python functions can be invoked from C# or other .NET languages via DLR hosting APIs. In a .NET application, the IronPython.Hosting namespace provides a ScriptEngine to create execution scopes, load Python scripts, and retrieve functions as dynamic objects or delegates for direct calls. Python functions further support conversion to .NET delegates using clr.ConvertToDelegate, allowing assignment to event handlers or callbacks, such as wiring a Python lambda to a .NET button's Click event. This mechanism preserves Python's dynamic nature while adhering to .NET's type system for events and multicast delegates.[3]
Interface Extensibility
IronPython enables Python developers to extend .NET functionality by implementing interfaces defined in C# or other .NET languages, allowing seamless integration of Python logic into .NET ecosystems. Python classes can directly inherit from .NET interfaces using standard inheritance syntax, with method implementations resolved dynamically at runtime by the Dynamic Language Runtime (DLR). For instance, a Python class can implement theSystem.ICloneable interface as follows:
import System
class MyClass(System.ICloneable):
def __init__(self, value):
self.value = value
def Clone(self):
return MyClass(self.value)
import System
class MyClass(System.ICloneable):
def __init__(self, value):
self.value = value
def Clone(self):
return MyClass(self.value)
ICloneable implementations.[38][15]
The DLR further supports the creation of runtime proxies for .NET types, facilitating dynamic interception and customization of method calls with Python callbacks. By leveraging DLR's expression trees and dynamic object services, developers can generate proxy instances that wrap .NET objects, injecting Python-defined behavior such as logging or validation without modifying the original types. This capability stems from the DLR's core features, which allow for late-bound operations and extensible meta-objects, making IronPython suitable for aspect-oriented extensions in .NET applications.[31]
Event handling provides another layer of extensibility, where Python functions can subscribe to .NET events using familiar operator syntax. .NET events are exposed as objects supporting __iadd__ and __isub__ methods, permitting the use of += and -= for attachment and detachment. A practical example involves monitoring file system changes:
from System.IO import FileSystemWatcher
watcher = FileSystemWatcher(".")
def on_created(sender, event_args):
print(f"Created: {event_args.Name} ({event_args.ChangeType})")
watcher.Created += on_created
watcher.EnableRaisingEvents = True
from System.IO import FileSystemWatcher
watcher = FileSystemWatcher(".")
def on_created(sender, event_args):
print(f"Created: {event_args.Name} ({event_args.ChangeType})")
watcher.Created += on_created
watcher.EnableRaisingEvents = True
System.Type.GetTypeFromProgID or interop assemblies, which treat properties and methods as Python attributes. However, support for Windows Runtime (WinRT) is partial, constrained by IronPython's reliance on .NET Framework or .NET Core runtimes, which lack native WinRT projections without additional bridging; this limits direct access in Universal Windows Platform scenarios compared to full .NET languages.[38]
Performance Analysis
Benchmark Comparisons
IronPython's performance in standard benchmarks reveals trade-offs inherent to its integration with the .NET runtime, often lagging behind CPython in pure Python execution while gaining advantages in .NET-interfacing scenarios. In the PyStone benchmark, which measures synthetic CPU performance, historical tests from around 2010 showed IronPython 2.x results comparable to or slightly better than CPython 2.x in some configurations.[49][42] However, IronPython generally performs worse than modern CPython versions like 3.12 on PyStone, reflecting ongoing optimizations in CPython's interpreter. Recent benchmarks for IronPython 3.4 are limited.[2] The Richards benchmark, a CPU-bound task simulating concurrent task scheduling, highlights similar disparities; IronPython has been slower than CPython in historical runs, though it outperforms in .NET-heavy workloads where native interop minimizes overhead, such as calling .NET APIs directly without marshalling costs.[49][42] Startup time represents a notable drawback for IronPython, typically slower than CPython due to the initial loading of the .NET Common Language Runtime (CLR) and assemblies. This penalty may be mitigated in later .NET versions, though benefits for IronPython's dynamic code are limited.[46][50] As of 2009, IronPython underperformed relative to Jython in pure Python benchmarks, with Jython executing tasks faster in Java-interop light scenarios, though both trailed CPython in raw speed. Recent comparisons are unavailable.[51] Comparisons with CPython enhanced by NumPy are not directly feasible, as IronPython lacks native support for CPython's C extensions, rendering NumPy incompatible without viable wrappers; projects like Ironclad are outdated.[52][30]Threading and Scalability Benefits
IronPython's implementation on the .NET Common Language Runtime (CLR) eliminates the Global Interpreter Lock (GIL) present in CPython, enabling true multi-threading where multiple Python threads can execute simultaneously across all available CPU cores.[43] This absence of the GIL stems from IronPython's reliance on the thread-safe libraries and runtime of .NET, unlike CPython's C-based extensions that necessitate the lock to prevent race conditions in memory management.[43] As a result, CPU-bound tasks in IronPython can achieve parallel execution, providing a significant advantage over CPython's effective single-core limitation for such workloads.[53] Through its seamless .NET integration, IronPython allows developers to leverage the Task Parallel Library (TPL) for implementing asynchronous and parallel operations directly in Python code.[38] For instance, TPL constructs likeParallel.ForEach can be invoked from IronPython scripts to process collections in parallel, enhancing efficiency for both CPU-intensive computations and I/O-bound tasks without the concurrency restrictions imposed by CPython's GIL.[54] This integration supports advanced patterns such as task continuations and cancellation tokens, making it particularly suitable for responsive applications involving asynchronous I/O.[55]
In scalability contexts, IronPython excels in high-concurrency environments like web servers built with ASP.NET, where .NET's robust threading model and automatic memory management handle enterprise-level loads effectively.[56] The CLR's garbage collector optimizes resource allocation across threads, reducing overhead in scenarios with numerous simultaneous requests, such as dynamic web applications or API services.[56] Community reports indicate improved multi-threaded performance in IronPython compared to CPython, particularly in environments utilizing multiple cores for parallel processing.[53]
Applications and Examples
Historical Deployments
IronPython was notably deployed in Silverlight applications for dynamic scripting within browser-based .NET applications from 2007 to 2012, enabling developers to build interactive user interfaces incorporating Python logic alongside Silverlight's multimedia capabilities.[17][57] This integration leveraged the Dynamic Language Runtime (DLR) to host IronPython scripts directly in Silverlight environments, facilitating rapid prototyping of rich web experiences such as animated controls and event-driven behaviors without requiring full recompilation.[58] In enterprise scripting contexts, IronPython integrates with Autodesk tools like AutoCAD and Revit for automation scripts, allowing users to extend CAD functionalities through Python-based macros and plugins that interact with the .NET API.[59][60] For instance, Revit's macro system uses IronPython 2.7 to execute scripts for tasks such as model manipulation and parameter adjustments, providing a more accessible alternative to C# for non-programmers in architectural workflows.[59] Following the deprecation of Silverlight, with Microsoft announcing no further major versions after Silverlight 5 in 2011 and full end of support on October 12, 2021, IronPython's role in such browser-centric deployments diminished significantly.[61] Remaining legacy uses persist in on-premise .NET Framework applications, where IronPython continues to serve as an embedded scripting engine for .NET 4.6.2 and earlier environments, particularly in internal tools and legacy automation systems.[2] Niche adoptions of IronPython included early game development via the XNA Framework, where it was explored as a scripting alternative to C# for prototyping game logic and behaviors in Windows-based titles during the late 2000s.[62] Developers embedded IronPython scripts into XNA projects to handle dynamic elements like AI behaviors or UI interactions, capitalizing on its interpretive nature for iterative testing without frequent rebuilds.[63] IronPython continues to see use in contemporary engineering and development tools. In Ansys simulation software, such as Workbench, Mechanical, and Discovery, IronPython serves as the basis for scripting to automate workflows, interact with .NET/Mono assemblies, and extend simulation capabilities, with support ongoing as of 2025.[64] Additionally, Microsoft Visual Studio provides project templates for IronPython applications, enabling .NET interop and mixed-mode debugging, facilitating its use in modern .NET development environments as of 2024.[65]Practical Code Examples
IronPython's practical utility is best illustrated through executable code snippets that leverage its seamless integration with the .NET Framework. These examples assume IronPython 3.x running on a .NET environment, such as Windows with Visual Studio or the IronPython standalone installer.[2] A foundational example demonstrates importing .NET assemblies and invoking basic console output, showcasing IronPython's ability to blend Python syntax with .NET functionality.import clr
clr.AddReference('System')
from System import Console
Console.WriteLine('Hello from IronPython!')
import clr
clr.AddReference('System')
from System import Console
Console.WriteLine('Hello from IronPython!')
clr module and uses the Console class to print to the standard output, confirming IronPython's runtime initialization and .NET interop.[66]
For deeper .NET integration, IronPython enables direct access to data access libraries like System.Data.SqlClient for database operations. The following snippet establishes a connection to a SQL Server instance and executes a simple query, illustrating how Pythonic code can manipulate .NET data objects without additional wrappers.
import clr
clr.AddReference('System.Data')
from System.Data.SqlClient import SqlConnection, SqlCommand
connection_string = 'Server=(localdb)\\mssqllocaldb;Database=TestDB;Trusted_Connection=True;'
conn = SqlConnection(connection_string)
conn.Open()
cmd = SqlCommand('SELECT COUNT(*) FROM Users', conn)
result = cmd.ExecuteScalar()
print(f'Number of users: {result}')
conn.Close()
import clr
clr.AddReference('System.Data')
from System.Data.SqlClient import SqlConnection, SqlCommand
connection_string = 'Server=(localdb)\\mssqllocaldb;Database=TestDB;Trusted_Connection=True;'
conn = SqlConnection(connection_string)
conn.Open()
cmd = SqlCommand('SELECT COUNT(*) FROM Users', conn)
result = cmd.ExecuteScalar()
print(f'Number of users: {result}')
conn.Close()
threading module. The demo below spawns multiple threads to perform independent computations, demonstrating scalable execution across cores.
import threading
import time
def compute_sum(n):
total = sum(range(n))
print(f'Thread {threading.current_thread().name}: Sum = {total}')
threads = []
for i in range(4):
t = threading.Thread(target=compute_sum, args=(1000000,))
threads.append(t)
t.start()
for t in threads:
t.join()
print('All threads completed.')
import threading
import time
def compute_sum(n):
total = sum(range(n))
print(f'Thread {threading.current_thread().name}: Sum = {total}')
threads = []
for i in range(4):
t = threading.Thread(target=compute_sum, args=(1000000,))
threads.append(t)
t.start()
for t in threads:
t.join()
print('All threads completed.')
import clr
clr.AddReference('System')
from System import Decimal, DivideByZeroException
try:
result = [Decimal](/page/Decimal)(10) / [Decimal](/page/Decimal)(0)
except DivideByZeroException as e:
print(f'Caught .NET exception: {e.Message}')
import clr
clr.AddReference('System')
from System import Decimal, DivideByZeroException
try:
result = [Decimal](/page/Decimal)(10) / [Decimal](/page/Decimal)(0)
except DivideByZeroException as e:
print(f'Caught .NET exception: {e.Message}')
DivideByZeroException from the .NET [Decimal](/page/Decimal) type, which is imported and caught specifically, printing the error message while preventing program termination.[38]
Licensing and Distribution
License History
IronPython's licensing origins trace back to its creation in 2005 by Jim Hugunin, who released the initial versions under personal permissive terms that allowed open-source distribution but were tailored specifically to him as the author.[13] These early releases were experimental and aimed at demonstrating Python's viability on the .NET Framework, with permissive conditions that facilitated community access without formal corporate oversight. Following Hugunin's recruitment to Microsoft in 2006, IronPython's version 1.x releases adopted the Shared Source License for IronPython, a permissive license that permitted commercial and noncommercial use, modification, and distribution while retaining Microsoft control over key aspects such as patent grants limited to the software itself.[15][68] This license marked IronPython's integration into Microsoft's ecosystem, emphasizing rapid iteration toward a stable 1.0 release while requiring retention of copyright notices and providing no warranties. With the release of IronPython 2.x starting in 2007, the project transitioned to the Microsoft Public License (Ms-PL), an OSI-approved permissive license that broadened contributor involvement by granting royalty-free rights to reproduce, modify, and distribute the software, though it maintained Microsoft's influence through explicit patent protections and trademark restrictions.[68][69] The Ms-PL applied through 2010, supporting versions up to 2.6 and enabling tighter .NET interoperability during this period of active Microsoft development. In July 2010, Microsoft relicensed IronPython under the Apache License 2.0 in response to community preferences, shifting to a fully OSI-approved open-source model that explicitly allowed broad commercial use, patent grants without termination risks from litigation, and compatibility with diverse ecosystems.[69][70] This change coincided with IronPython 2.7 Alpha 1 and facilitated the project's move to GitHub in 2011 under the IronLanguages organization, decentralizing maintenance and enhancing collaborative contributions.[18]Current Terms and Availability
IronPython is distributed under the Apache License 2.0, which grants users a perpetual, worldwide, non-exclusive, no-charge, royalty-free license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute the software in source or object form, including for commercial purposes. This license requires that copyright notices, the original license terms, and any conditions regarding patent grants be retained in any redistributed copies, along with attribution to the .NET Foundation and contributors if applicable. It provides the software on an "as is" basis, disclaiming all warranties, express or implied, including those of merchantability, fitness for a particular purpose, and non-infringement, while limiting liability for any damages arising from its use. Binaries for IronPython are available through GitHub releases, including MSI installers for Windows, ZIP archives for cross-platform use, DEB packages for Debian-based Linux distributions, and PKG installers for macOS.[71] For integration into .NET projects, IronPython is distributed as a NuGet package, enabling easy embedding of the IronPython engine via tools like the .NET CLI or Visual Studio package manager.[21] The complete source code is hosted on GitHub, allowing users to clone the repositories, build from source using provided scripts such asmake.ps1, and customize as needed.[2] Direct installation via pip install ironpython is not supported, as IronPython is not hosted on PyPI; instead, users must download binaries or use .NET tooling like dotnet tool install --global ironpython.console for console access.[71]
Development occurs across separate repositories for distinct Python versions: the ironpython2 repository maintains the legacy Python 2.7 implementation, while ironpython3 focuses on active development for Python 3.x, currently targeting compatibility with Python 3.4 and incorporating features like Unicode strings and a reorganized standard library.[2] The latest release in the Python 3.x branch is version 3.4.2 (December 2024), with binaries supporting .NET Framework 4.6.2 and later, as well as .NET Core and .NET 5+ runtimes.[23]
IronPython's Apache 2.0 license is compatible with the MIT license under which much of the .NET ecosystem is released, permitting seamless integration without additional licensing conflicts. There are no specific restrictions on usage with .NET Core or later versions, and it supports deployment on .NET 6.0, .NET 8.0, and equivalent Mono runtimes across Windows, Linux, and macOS platforms.[2] Once installed, package management within IronPython environments is handled via ipy -m pip, allowing installation of compatible Python modules in user-global, project-local, or virtual environments.[71]