Skip to: site menu | section menu | main content
Follow Michael on:
Back to top
IronPython is a radical project for Microsoft. It is the first project to be released under their Ms-PL (Microsoft Public License) open source license. It is also a radically different language from the ones that Microsoft has traditionally promoted for the .NET framework. IronPython is an implementation of the popular programming language Python for .NET. Python is an open source, object-oriented, dynamically typed language in use by organizations like Google, NASA and Pixar. Python is a multi-paradigm language, and brings new possibilities to .NET programmers: not just the added flexibility of dynamic typing, but programming styles such as functional programming and metaprogramming. For Python programmers the powerful runtime, with its JIT compiler and huge range of .NET libraries, also presents new opportunities.
The goal of IronPython in Action is not just to teach the mechanics of using IronPython, but to demonstrate the power and effectiveness of object-oriented programming in the Python language. To this end we cover best practices in API design, testing, and the use of design patterns in structured application development. In part this is to dispel the myth that dynamic languages are merely scripting languages; but mostly it is to help you make the best of the language and the platform on which it runs.
The addition of Python to the range of languages available as first-class citizens in .NET reflects the changes happening in the wider world of programming. No one says it better than Anders Hejlsberg, the architect of C#, when asked by Computer World what advice he had for up-and-coming programmers:
Go look at dynamic languages and meta-programming: those are really interesting concepts. Once you get an understanding of these different kinds of programming and the philosophies that underlie them, you can get a much more coherent picture of what’s going on and the different styles of programming that might be more appropriate for you with what you’re doing right now.
Anyone programming today should check out functional programming and meta-programming as they are very important trends going forward.
IronPython in Action is particularly aimed at two types of programmers: Python programmers looking to take advantage of the power of the .NET framework or Mono for their applications, and .NET programmers interested in the flexibility of dynamic languages. It assumes no experience of either Python or .NET, but does assume some previous programming experience. If you have some programming experience, but have never used either of these systems, you should find IronPython in Action an accessible introduction to both Python and .NET.
Just as Python is suited to an enormous range of problem domains, so is IronPython. The book covers a range of different uses of IronPython: from web development to application development, one-off scripting to system administration, and embedding into .NET applications for extensible architectures or providing user scripting.
IronPython in Action is available from:
You can use the code ironpython35 for a 35% discount off IronPython in Action from Manning (both ebook and print book).
You can get the sourcecode that accompanies the book from the Download Page.
Part 1: Getting Started with IronPython
1.1 An Introduction to IronPython
1.1.1 What is IronPython?1.1.2 A Brief History of IronPython1.1.3 IronPython for Python Programmers1.1.4 IronPython for .NET Programmers1.2 Python on the CLR
1.2.1 Dynamic Languages on .NET and the DLR1.2.2 Silverlight, a New CLR1.2.3 The Python Programming Language1.2.4 Multiple Programming Paradigms1.3 Live Objects on the Console - the Interactive Interpreter
1.3.1 Using the Interactive Interpreter1.3.2 .NET Framework: assemblies, namespaces and classes1.3.3 Live objects and the Interactive Interpreter1.3.4 Object Introspection with dir and help1.4 Summary
Introduction to Python
2.1 An Overview of Python
2.1.1 Python datatypes2.1.2 Names, Objects and References2.1.3 Mutable and immutable objects2.2 Python: Basic Constructs
2.2.1 Statements and expressions2.2.2 Conditionals and loops2.2.3 Functions2.2.4 Built in Functions2.2.5 Classes2.3 Additional Python Features
2.3.1 Exception Handling2.3.2 Closures and scoping rules2.3.3 List Comprehensions2.3.4 Modules, Packages and Importing2.3.5 Docstrings2.3.6 The Python Standard Library2.4 Summary
.NET Objects & IronPython
3.1 Introducing .NET
3.1.1 Translating MSDN Documentation into IronPython3.1.2 The Form Class3.2 Structures, Enumerations and Collections: .NET Types
3.2.1 Methods and properties inherited from Control3.2.2 Adding a Label to the Form: ControlCollection3.2.3 Configuring the Label: The Color Structure3.2.4 The FormBorderStyle Enumeration3.2.5 Hello World with Form and Label3.3 Handling Events
3.3.1 The MouseMove Event3.3.2 Event Handlers in IronPython3.4 Subclassing .NET Types
3.5 Summary
Part 2: Core Development Techniques
Writing an Application, and Design Patterns with IronPython
4.1 Data Modelling and Duck Typing
4.1.1 Python and Protocols4.1.2 Duck Typing in Action4.2 Model View Controller in IronPython
4.2.1 Introducing the Running Example4.2.2 The View Layer: Creating a User Interface4.2.3 A Data Model4.2.4 A Controller Class4.3 The Command Pattern
4.3.1 The SaveFileDialog4.3.2 Writing Files: the .NET & Python Ways4.3.3 Handling exceptions and the system message box4.3.4 The Save Command, a Python Class4.3.5 The SaveAs Command4.4 Integrating Commands with Our Running Example
4.4.1 Menu Classes and Lambda4.4.2 Toolbar and Images, .NET Classes4.4.3 Bringing the GUI to Life4.5 Summary
First Class Functions in Action with XML
5.1 First Class Functions
5.1.1 Higher Order Functions5.1.2 Python Decorators5.1.3 A Null Argument Checking Decorator5.2 Representing Documents with XML
5.2.1 The .NET XmlWriter5.2.2 A DocumentWriter Class5.2.3 An Alternative with an Inner Function5.3 Reading XML
5.3.1 XmlReader5.3.2 An IronPython XML Document Reader5.4 Handler Functions for MultiDoc XML
5.5 The Open Command
5.6 Summary
Properties, Dialogs and Visual Studio
6.1 Document Observers
6.1.1 Python properties6.1.2 Document Observers on the MainForm6.1.3 Adding the OpenCommand6.2 More with TabPages: Dialogs and Visual Studio
6.2.1 Remove Pages: Ok and Cancel Dialog6.2.2 Rename Pages: A Modal Dialog6.2.3 Visual Studio Express and IronPython6.2.4 Adding Pages: Code Reuse in Action6.2.5 Wiring the Commands to the View6.3 Object Serializing with BinaryFormatter
6.4 Summary
Agile Testing - Where Dynamic Typing Shines
7.1 The unitest module
7.1.1 Creating a TestCase7.1.2 setup and tearDown7.1.3 Test Suites with Multiple Modules7.2.Testing with Mocks
7.2.1 Mock Objects7.2.2 Modifying Live Objects: The Art of the Monkey Patch7.2.3 Mocks and Dependency Injection7.3 Functional Testing
7.3.1 Interacting with the GUI Thread7.3.2 An AsyncExecutor for Asynchronous Interactions7.3.3 The Functional Test: Making MultiDoc Dance7.4 Summary
Getting Deeper into IronPython: Metaprogramming, Protocols and More
8.1 Protocols instead of Interfaces
8.1.1 A Myriad of Magic Methods8.1.2 Operator Overloading8.1.3 Iteration8.1.4 Generators8.1.5 Equality and Inequality8.2 Dynamic Attribute Access
8.2.1 Attribute Access through Builtin Functions8.2.2 Attribute Access through Magic Methods8.2.3 Proxying Attribute Access8.3 Metaprogramming
8.3.1 Introduction to Metaclasses8.3.2 Uses of Metaclasses8.3.3 A Profiling Metaclass8.4 IronPython and the CLR
8.4.1 .NET Arrays8.4.2 Overloaded Methods8.4.3 'out', 'ref', 'params' and Pointer Parameters8.4.4 Value Types8.4.5 Interfaces8.4.6 Attributes8.5.Summary
Part 3: IronPython and Advanced .NET
WPF and IronPython
9.1 Hello World with WPF and IronPython
9.1.1 WPF from Code9.1.2 Hello World from XAML9.2 WPF in Action
9.2.1 Layout with the Grid9.2.2 The WPF ComboBox and CheckBox9.2.3 The Image Control9.2.4 The Expander9.2.5 The ScrollViewer9.2.6 The TextBlock a Lightweight Document Viewer9.2.7 The XamlWriter9.3 XPS Documents and Flow Content
9.3.1 FlowDocument Viewer Classes9.3.2 Flow Document Markup9.3.3 Document XAML and Object Tree Processing9.4 Summary
Windows System Administration with IronPython
10.1 System Administration with IronPython
10.1.1 Simple Scripts10.1.2 Shell Scripting with IronPython
10.2. WMI and the System.Management Assembly
10.2.1 System.Management10.2.2 Connecting to remote Computers
10.3 Powershell & IronPython
10.3.1. Using Powershell from IronPython10.3.2. Using IronPython inside Powershell
10.4 Summary
IronPython and ASP.NET
11.1 Introducing ASP.NET
11.1.1 Web controls11.1.2 Pages and user controls11.1.3 Rendering, server code and the page lifecycle
11.2 Adding IronPython to ASP.NET
11.2.1 Writing a first application11.2.2 Creating a project
11.3 ASP.NET Infrastructure
11.3.1 The App_Script Folder11.3.2 The Global.py File11.3.3 The Web.config File
11.4 A Web-based MultiDoc Viewer
11.4.1 Page Structure11.4.2 Code-behind
11.5 Editing MultiDocs
11.5.1 Swapping Controls11.5.2 Handling Viewstate11.5.3 Additional Events
11.6 Converting the Editor into a User Control
11.6.1 Viewstate Again11.6.2 Adding Parameters
11.7 Summary
Databases and Web Services
12.1 Relational databases and ADO.NET
12.1.1 Trying it out using PostgreSQL12.1.2 Connecting to the database12.1.3 Executing commands12.1.4 Setting parameters12.1.5 Querying the database12.1.6 Reading multi-row results12.1.7 Using transactions12.1.8 DataSets12.1.9 Databinding
12.2 Web services
12.2.1 Using a simple web service12.2.2 Using SOAP services from IronPython12.2.3 REST services in IronPython
12.3 Summary
Silverlight: IronPython in the Browser
13.1. Introduction to Silverlight
13.1.1. Dynamic Silverlight13.1.2. Your Python Application13.1.3. Silverlight Controls13.1.4. Packaging a Silverlight Application13.2. A Silverlight Twitter Client
13.2.1. Cross Domain Policies13.2.2. Debugging Silverlight Applications13.2.3. The User Interface and a Password TextBox13.2.4. Accessing Network Resources13.2.5. Threading and Dispatching onto the UI Thread13.2.6. IsolatedStorage in the Browser13.3. Videos and the Browser DOM
13.3.1. The MediaElement Video Player13.3.2. Interacting with the Browser DOM13.4. Summary
Part 4: Reaching Out with IronPython
14.1. Writing a Class Library for IronPython
14.1.1. Working with Visual Studio or MonoDevelop14.1.2. Python Objects from Class Libraries14.1.3. Calling Unmanaged Code with the P/Invoke Attribute14.1.4. Methods with Attributes through Subclassing14.2. Creating Dynamic (and Pythonic) Objects from C# / VB.NET
14.2.1. Creating Dynamic Objects14.2.2. Python Magic Methods14.2.3. APIs with Keyword and Multiple Arguments14.3. Compiling and Using Assemblies at Runtime
14.4. Summary
15.1. Creating a custom Executable
15.1.1. The IronPython Engine15.1.2. Executing a Python File15.2. IronPython as a Scripting Engine
15.2.1. Setting and Fetching Variables from a Scope15.2.2. Providing Modules and Assemblies for the Engine15.2.3. Python Code as an Embedded Resource15.3. Python Plugins for .NET Applications
15.3.1. A Plugin Class and Registry15.3.2. Auto-discovery of User Plugins15.3.3. Calling the User Plugins15.4. Using DLR Objects from Other .NET Languages
15.4.1. Expressions, Functions and Python Types15.4.2. Dynamic Operations with ObjectOperations15.4.3. The Builtin Python Functions and Modules15.5. Summary