Back to Blog

CDM Python Generator: Bridging the Common Domain Model and the Python communities

In the ever-evolving world of financial transactions, the Common Domain Model (CDM)  is now available in Python. Explore how this initiative is evolving to enhance data consistency and interoperability in the financial industry.


The Common Domain Model (CDM) is an initiative, managed by FINOS, designed to provide a standard representation of events and actions that occur during the lifecycle of a financial transaction. The goal of the CDM is to enhance the consistency and interoperability of data and processes across various platforms, systems, and solutions in the financial market.

The CDM is developed using a Domain Specific Language (DSL) and it is distributed across the financial industry in multiple languages, including Java, DAML, Scala, C#, Go, and TypeScript. The level of completeness of the distributions across these languages varies, being Java the most complete CDM distribution. 


CDM was missing a Python distribution. We, as TradeHeader, saw having a CDM Python distribution in the critical path for being able to support many use cases using CDM. Python is heavily used in applications such as Machine Learning (ML) and pricing and risk libraries. In addition, the community of Python developers is huge and growing exponentially.

We decided to fill out the gap and implement a fully open source CDM Python Generator in collaboration with two other fintech firms, CloudRisk and FT Advisory.

First Phase

The CDM Python Generator successfully converts Rosetta Objects, their expressions, and enumerated lists (Enums), ensuring a smooth transition between Rosetta and Python environments. This integration offers developers the ability to leverage Python's extensive libraries and tools, while still maintaining the consistency and standardization that CDM brings. We completed this first phase in August of 2023 when FINOS released the Python CDM distribution using the Generator.

Generation Process

At the heart of our generator is the `` main class. This class encompasses other crucial generators, such as the `ObjectGenerator`, `EnumGenerator`, and `FunctionGenerator`. 

  • ObjectGenerator: Tasked with creating the class structure derived from the RosettaObject, this generator manages the fields. Furthermore, it is also responsible for generating the necessary metadata.
  • ExpressionGenerator: Manages the conversion of conditional logic and constraints from CDM into Python code. This includes checks for optionality, choices, and other attribute-related conditions.
  • EnumGenerator: Responsible for converting CDM enums into Python enums. It maps each CDM enum value to its Python counterpart
  • FunctionGenerator: As of now, this generator's role is confined to crafting the basic function structure. It shapes the method declaration with its associated attributes. However, the content within these functions is currently designated as a 'pass', indicating a placeholder for future development.


  • Interoperability:  The generator facilitates easy transitioning between the standard models of CDM and Python’s dynamic environment.
  • Efficiency:  Python's vast libraries can be utilized to enhance the functionalities of CDM implementations.
  • Standardization with Flexibility:  While CDM ensures that financial processes and events are uniformly represented, Python's adaptability allows developers to implement custom solutions when needed.

Conversion Example

This is a simple example of an object in CDM defined using the functional DSL (Domain Specific Language) syntax:


As the functional code specifies, the PeriodRange type contains two optional attributes: lowerBound and upperBound. In addition, there is a condition that checks that at least one of the two attributes is present in the CDM object.

Python boasts simplicity in its syntax, making it easy to read and understand. This is the conversion from the CDM DSL object to Python:

code tradeheader

Pydantic Library

One of the pivotal challenges in transitioning CDM's logic to Python is addressing the intricacies of cardinality. The CDM's cardinality representations do not have a direct counterpart in Python's type system. To navigate this challenge we use the Pydantic Library in the Generator. The Pydantic Library is a data validation and settings management tool for Python. Pydantic has been instrumental in defining clear data structures in Python that mirror the cardinality constraints present in CDM. This ensures data integrity and consistency when working with Rosetta Objects in Python.

Second Phase

We are already working on a second phase of the project further enhancing the capabilities of the CDM Python Generator. Here are the detailed next steps we are following:

  1. Function Conversion Expansion: While the current `FunctionGenerator` provides a basic structure for functions, our priority is to develop its capabilities to translate the intricate logic encapsulated within Rosetta functions into Python. This will involve diving deep into the functional constructs of Rosetta and mapping them efficiently to Python.

  2. Metadata Handling Improvements: The `ObjectGenerator` currently manages metadata generation. We aim to refine this process, ensuring that metadata generated is both accurate and provides meaningful context in the Python environment.

  3. Community Feedback Integration: Engaging with both the Rosetta and Python communities is essential. By gathering their feedback and understanding their needs, we can iterate on the generator to better suit real-world applications.

RepoHack 2023

Last month the winning team of the RepoHack 2023, The London Reporting House, used our CDM Python Generator as the basis for their solution. This was also a “victory” for us at TradeHeader since our initial goal was to provide a framework that could be used for many different CDM implementations.

Our aim isn't just to provide a tool once, but to refine it continuously and ensure that it becomes a reliable asset for developers working using CDM in Python.

To be informed of more content like this, subscribe to our blog!