---
title: "CDM Python Generator: Bridging the Common Domain Model and the Python communities"
description: The Common Domain Model (CDM), is a standard and machine-executable model for how financial products are managed across the transaction lifecycle.
image: https://www.tradeheader.com/hubfs/phyton-tradeheader.jpg
---

[Skip to content](https://www.tradeheader.com/blog/cdm-python-generator-tradeheader#main-content)

[![TradeHeader 15anys](https://www.tradeheader.com/hs-fs/hubfs/TradeHeader%2015anys.png?width=2407&height=729&name=TradeHeader%2015anys.png "TradeHeader 15anys")](https://www.tradeheader.com/)

- [INDUSTRIES](https://www.tradeheader.com/industries) 
    - [Capital Markets](https://www.tradeheader.com/capital-markets)
    - [Regulatory Reporting](https://www.tradeheader.com/regulatory-reporting)
    - [Payments](https://www.tradeheader.com/payments)
    - [Case Studies](https://www.tradeheader.com/blog/tag/case-studies)
- [SERVICES](https://www.tradeheader.com/services-consulting-training-development) 
    - [Consulting](https://www.tradeheader.com/consulting-fpml)
    - [Standards Training](https://www.tradeheader.com/standards-training-cdm-drr-iso20022-fpml-fix)
    - [Development](https://www.tradeheader.com/custom-software-development) 
          - [Service Tools List](https://www.tradeheader.com/service-tools-list)
- [PRODUCTS](https://www.tradeheader.com/products-tradeheader)
- [NEWS & INSIGHTS](https://www.tradeheader.com/blog)
- [ABOUT US](https://www.tradeheader.com/about-us) 
    - [About](https://www.tradeheader.com/about-us)
    - [Core Values](https://www.tradeheader.com/core-values)
    - [Our Partners](https://www.tradeheader.com/tradeheader-partners)
    - [Team](https://www.tradeheader.com/team)
    - [Awards](https://www.tradeheader.com/awards)
- [WORK WITH US](https://www.tradeheader.com/join-the-tradeheader-team-consultant) 
    - [Consultant](https://www.tradeheader.com/join-the-tradeheader-team-consultant)
    - [Software Engineer](https://www.tradeheader.com/join-tradeheader-software-engineer)
- [CONTACT](https://www.tradeheader.com/tradeheader-contact)

- [CDM](https://www.tradeheader.com/blog/tag/cdm),
- [TradeHeader](https://www.tradeheader.com/blog/tag/tradeheader),
- [Innovation](https://www.tradeheader.com/blog/tag/innovation),
- [Python](https://www.tradeheader.com/blog/tag/python),
- [Code Generator](https://www.tradeheader.com/blog/tag/code-generator),
- [Insights](https://www.tradeheader.com/blog/tag/insights)

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

![](https://www.tradeheader.com/hubfs/phyton-tradeheader.jpg)

- November 15, 2023

![David Carrascosa, Manuel Martos & Marc Gratacós](https://www.tradeheader.com/hubfs/tradeheader_logo-1.png)

[ David Carrascosa, Manuel Martos & Marc Gratacós ](https://www.tradeheader.com/blog/author/david-carrascosa-manuel-martos-marc-gratacós)

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.

# **Background**

The [Common Domain Model](https://www.finos.org/common-domain-model) (CDM) is an initiative, managed by [FINOS](https://www.finos.org/), 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, with Java being the most complete CDM distribution. 

# **![CDM-Code-Generators_Tradeheader](https://www.tradeheader.com/hs-fs/hubfs/CDM-Code-Generators_Tradeheader.jpg?width=710&height=419&name=CDM-Code-Generators_Tradeheader.jpg)**

CDM was missing a Python distribution which seemed to be critically limiting the adoption of the technology. A CDM Python distribution was 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.

This group decided that it was important to close the gap by implementing a fully open-source CDM Python Generator. The [International Swaps and Derivatives Association (ISDA)](https://www.isda.org), the initial sponsor of CDM, put TradeHeader in contact with two other fintech firms, [CloudRisk](https://www.cloudrisk.uk) and [FT Advisory](https://www.ftadvisory.co/), and our collaboration started.

# **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. The three firms completed this first phase in August of 2023 enabling [FINOS to release the Python CDM distribution](https://www.finos.org/blog/cdm-now-available-in-python) using the Generator.

## **Generation Process**

At the heart of this generator is the `PythonCodeGenerator.java` 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.

## **Advantages**

- **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:

![image1](https://www.tradeheader.com/hs-fs/hubfs/image1.png?width=539&height=118&name=image1.png)

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](https://www.tradeheader.com/hs-fs/hubfs/pasted%20image%200.png?width=840&height=320&name=pasted%20image%200.png)

# **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](https://docs.pydantic.dev/latest/) 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**

The three firms 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](https://www.tradeheader.com/blog/repohack-2023-exploring-innovative-solutions-for-the-repo-industry), The [London Reporting House](https://londonreportinghouse.com/), used the CDM Python Generator as the basis for their solution. This was also a “victory” for [CloudRisk](https://www.cloudrisk.uk), [FT Advisory](https://ftadvisory.co), and 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.

 Subscribe for

### Sign Up for our Blog

Stay updated with our latest posts. Subscribe to our blog!

 Blog Post

## Related Articles

If you found this article interesting, here are some others that can expand your knowledge on the topic.

[![](https://www.tradeheader.com/hubfs/tradheader_scrum.png) ](https://www.tradeheader.com/blog/key-points-of-agile-and-scrum-at-tradeheader)

[Scrum](https://www.tradeheader.com/blog/tag/scrum), [Agile](https://www.tradeheader.com/blog/tag/agile), [TradeHeader](https://www.tradeheader.com/blog/tag/tradeheader), [Events](https://www.tradeheader.com/blog/tag/events)

### [ Key points of Agile and Scrum at TradeHeader ](https://www.tradeheader.com/blog/key-points-of-agile-and-scrum-at-tradeheader)

 June 19, 2023

 Agile methodologies have emerged as a game-changer, revolutionizing the way teams collaborate and deliver exceptional...

[ Read more ](https://www.tradeheader.com/blog/key-points-of-agile-and-scrum-at-tradeheader)

[![](https://www.tradeheader.com/hubfs/regcast_mifir-1.jpg) ](https://www.tradeheader.com/blog/regcast-mifir-correlation-cost-and-control-your-live-inspection-has-started)

[FpML](https://www.tradeheader.com/blog/tag/fpml), [Insights](https://www.tradeheader.com/blog/tag/insights), [MiFIR Reporting](https://www.tradeheader.com/blog/tag/mifir-reporting), [Data Quality](https://www.tradeheader.com/blog/tag/data-quality), [Regulatory Supervision](https://www.tradeheader.com/blog/tag/regulatory-supervision)

### [ REGCast: MiFIR Correlation, Cost and Control: Your Live Inspection Has Started ](https://www.tradeheader.com/blog/regcast-mifir-correlation-cost-and-control-your-live-inspection-has-started)

 February 12, 2026

 MiFIR reporting has entered live supervision — and data quality is now a supervisory judgement.

[ Read more ](https://www.tradeheader.com/blog/regcast-mifir-correlation-cost-and-control-your-live-inspection-has-started)

[![](https://www.tradeheader.com/hubfs/th_finos_logo-1.jpg) ](https://www.tradeheader.com/blog/from-standards-to-impact-cdm-becomes-an-active-finos-project)

[CDM](https://www.tradeheader.com/blog/tag/cdm), [TradeHeader](https://www.tradeheader.com/blog/tag/tradeheader), [FINOS](https://www.tradeheader.com/blog/tag/finos), [News](https://www.tradeheader.com/blog/tag/news)

### [ From Standards to Impact: CDM Becomes an Active FINOS Project ](https://www.tradeheader.com/blog/from-standards-to-impact-cdm-becomes-an-active-finos-project)

 October 21, 2025

 Advancing the FINOS mission to enable financial institutions to scale, modernize, and enhance profitability through...

[ Read more ](https://www.tradeheader.com/blog/from-standards-to-impact-cdm-becomes-an-active-finos-project)

 Check all articles

[![TradeHeader-15anys](https://www.tradeheader.com/hs-fs/hubfs/TradeHeader-15anys.png?width=210&height=64&name=TradeHeader-15anys.png "TradeHeader-15anys")](https://www.tradeheader.com/)

**UK:** +44 (0)20 3769 3053  
**Spain:** +34 619 831 118  
**US:** +1 (917) 932-0752

[info@tradeheader.com](https://web.archive.org/web/20250219105540/mailto:info@tradeheader.com)

[Follow us on LinkedIn ](https://es.linkedin.com/company/tradeheader) [Follow us on Twitter ](https://x.com/tradeheader) [Follow us on Facebook ](https://www.youtube.com/user/tradeHeader)

![ateam_tradeheader](https://www.tradeheader.com/hs-fs/hubfs/ateam_tradeheader.jpg?width=250&height=116&name=ateam_tradeheader.jpg "ateam_tradeheader")

#### SERVICES

- [Consulting](https://www.tradeheader.com/consulting-fpml)
- [Standards](https://www.tradeheader.com/standards-training-cdm-drr-iso20022-fpml-fix)
- [Development](https://www.tradeheader.com/custom-software-development)

#### PRODUCTS

- [ISO 20022 Validator](https://www.tradeheader.com/iso20022-validator)
- [FpML Validator](https://www.tradeheader.com/fpml-validator)
- [Product Classifier](https://www.tradeheader.com/product-classifier)
- [FpML to JSON Converter](https://www.tradeheader.com/fpml-to-json)
- [FpML to ISIN JSON Generator](https://www.tradeheader.com/fpml-to-isin)

#### ABOUT US

- [About](https://www.tradeheader.com/about-us)
- [Core Values](https://www.tradeheader.com/core-values)
- [Team](https://www.tradeheader.com/team)
- [Our Partners](https://www.tradeheader.com/tradeheader-partners)

#### NEWS & INSIGHTS

- [Market Insights](https://www.tradeheader.com/blog/tag/insights)
- [News](https://www.tradeheader.com/blog/tag/news)
- [Events](https://www.tradeheader.com/blog/tag/events)

#### DOWNLOAD BROCHURE

Copyright © TradeHeader 2026. All Rights Reserved | [Legal Notice](https://www.tradeheader.com/legal-notice) |[Information Security Policy - (PDF, in Spanish)](https://www.tradeheader.com/hubfs/politica_seguridad_informacion.pdf) |[Privacy Policy](https://www.tradeheader.com/privacy-policy) | Cookies Policy

![](https://px.ads.linkedin.com/collect/?pid=3868098&fmt=gif)