The Rune Python Generator creates Python code from Rune. It fully supports the Rune type syntax and has comprehensive expression coverage, though function generation is not yet fully implemented.
The generated code requires the RunePythonRuntime library and Python 3.11+.
Releases are triggered manually and follow a four-part semantic versioning scheme (x.y.z.n). The first three numbers match the rosetta.dsl.version in the pom.xml, and the fourth number tracks generator changes.
For example, when the DSL version updates to 9.64.1, the first release will be tagged 9.64.1.0. Subsequent releases will only increment the fourth digit (e.g., 9.64.1.1) until the DSL version changes again.
Releases should not be manually tagged.
The features of the current version can be found in the release notes
The Renovate bot automatically handles DSL updates by creating a pull request. Maintainers can merge this PR if it passes the automated build and unit tests. Manual changes including a new PR are required if the tests fail.
README.md- this file, for documentation purposesRELEASE.md- information about the current releasesrc/main- Java/Xtend code to generate Python from Runesrc/test- Java/Xtend code to run JUnit tests on the code generation processdocs/BUILD_AND_TEST.md- instructions on building and testing the repotest- Python unit tests of the generated code
This guide is meant for everyone who wants to contribute to the Rune Python Generator and needs to get things up and running.
Detailed build and testing instructions can be found in docs/BUILD_AND_TEST.md
Troubleshooting: If you run into issues, please open an issue. This helps us improve the guide for everyone.
- Indentation: Since Python is sensitive to indentation, ensure your submission uses four spaces for each indentation instead of tabs.
- Java vs xTend: since the intention is to replace xTend, all new code should be written in Java. Ideally, changes to existing code will migrate xTend code to Java.
Start by cloning the project: git clone https://github.com/finos/rune-python-generator
Our project runs with Java 21. Make sure that your Maven also uses this version of Java by running mvn -v.
To build the project, run mvn clean package.
Building the project using Maven will run JUNIT-based unit tests. All tests should pass. To run the Python unit tests follow the instructions in docs/BUILD_AND_TEST.md
Install version 2025-06 of the "Eclipse IDE for Java and DSL Developers" using the Eclipse Installer. You might have to enable "Advanced Mode" in the settings of the Eclipse Installer to install a specific version.
Xtend files cannot be built with any Java version later than 21. In Eclipse, go to Settings... > Java > Installed JREs and make sure the checked JRE points to a Java version of 21.
We use Checkstyle for enforcing good coding practices. The Eclipse plugin for Checkstyle can be found here: https://checkstyle.org/eclipse-cs/#!/.
Go to Import... > Existing Maven Project, select the right folder, click Finish.
To generate Python code from a single file or directory, after building the project use the standalone CLI by executing the following command:
java -cp target/python-0.0.0.main-SNAPSHOT.jar com.regnosys.rosetta.generator.python.PythonCodeGeneratorCLIThe generated code carries the licence terms of the model it was generated from, not those of the generator. Pass the model's SPDX tag-value file (for example its LICENSE.spdx) with -l / --license-file:
java -cp target/python-0.0.0.main-SNAPSHOT.jar com.regnosys.rosetta.generator.python.PythonCodeGeneratorCLI \
-s <rosetta-dir> -t <target-dir> -p <project-name> -v <version> -l <model>/LICENSE.spdxThe generator reads these fields and ignores all others:
| SPDX field | Required | Used for |
|---|---|---|
PackageLicenseDeclared |
yes | the SPDX-License-Identifier line of the header, and license in pyproject.toml |
PackageCopyrightText |
yes | the copyright line(s) of the header; a multi-line <text>...</text> value is written line by line |
PackageName, PackageHomePage |
no | an attribution line, Generated from <name> <version> (<home page>), written only when both are present |
PackageOriginator |
no | authors in pyproject.toml, from Organization: <name> (<email>) or Person: <name> (<email>); the email is optional |
The header is written at the top of every generated .py and .toml file. Files copied from --native-dir are left unchanged.
Licence terms are written only when both required fields are present. A field that is missing, empty, NONE or NOASSERTION is reported as a warning:
- A required field is missing: a warning names it, and no licence terms are written at all: no header, and no
licenseorauthorsinpyproject.toml. Generation continues. - An optional field is missing: a warning names it, and only the output that depends on it is left out.
- No
-lgiven: a warning says that no licence terms will be written.
A licence file that cannot be read, or that is not a well-formed SPDX tag-value file, stops the CLI with an error and nothing is generated. A file is not well formed when it has a line that is not Tag: value, a comment (#) or blank, when a <text> value has no closing </text>, or when it has none of the tags SPDXVersion, DataLicense, SPDXID or Package* (for example a LICENSE.md, or an SPDX document in JSON or RDF).
The generated Python classes are standard Pydantic v2 models that extend BaseDataClass from the rune-python-runtime. Each generated package exposes a rune_deserialize helper and every model instance exposes rune_serialize.
Import and instantiate a generated class like any Pydantic model:
from finos.cdm.base.math.UnitType import UnitType
from finos.cdm.base.math.FinancialUnitEnum import FinancialUnitEnum
unit = UnitType(financialUnit=FinancialUnitEnum.SHARE)Call rune_serialize() on any root model object. The method validates the model, then returns a compact or indented JSON string that includes the Rune @type, @model, and @version fields required for round-trip deserialization.
json_str = unit.rune_serialize(indent=2)
# {
# "@type": "cdm.base.math.UnitType",
# "@model": "cdm",
# "@version": "0.0.0",
# "financialUnit": "Share"
# }To skip pre-serialization validation (for example when working with incomplete objects during construction):
json_str = unit.rune_serialize(validate_model=False)Use the package-level rune_deserialize wrapper rather than calling model_validate directly. The wrapper resolves the correct namespace prefix so that @type strings in the JSON map to the right Python class:
import finos
obj = finos.rune_deserialize(json_str)
print(type(obj).__name__) # UnitType
print(obj.financialUnit) # FinancialUnitEnum.SHAREPass validate_model=False to skip post-deserialization constraint checking (useful when ingesting data that may not yet satisfy all conditions):
obj = finos.rune_deserialize(json_str, validate_model=False)The function accepts either a JSON string or a pre-parsed dict.
To generate the Python version of the Common Domain Model (CDM), use the build_cdm.sh script. This script uses the branch specified in the file and creates a wheel in target/python-cdm.
test/cdm_tests/cdm_setup/build_cdm.shTo use a different version of CDM, simply update the CDM_VERSION variable in the script.
The project roadmap is aligned with the Rune-DSL and CDM roadmaps.
We welcome contributions! Please follow these steps to get started:
- Fork the repository (https://github.com/finos/rune-python-generator/fork)
- Create your feature branch (
git checkout -b feature/fooBar) - Read our contribution guidelines and Community Code of Conduct
- Commit your changes (
git commit -am 'Add some fooBar') - Push to the branch (
git push origin feature/fooBar) - Create a new Pull Request: the intention is to ensure that Main is always production ready and matches a release.
- Simple / short running changes : the PR should be to Main
- Complex / long running changes: the recommendation is to complete all the changes in a staging branch, such as Develop or another branch of your choosing. Once the change is complete and passes all tests, then raise the PR to main from your staging branch.
NOTE: FINOS repositories require an executed and active FINOS Individual Contributor License Agreement (ICLA) or an executed and active FINOS Corporate Contribution License Agreement (CCLA). The FINOS Clabot tool (or EasyCLA) will flag and block commits from individuals not covered. Please note that some CCLAs require individuals/employees to be explicitly named on the CCLA.
If you are unsure if you are covered under an existing CCLA send an email to help@finos.org
Get in touch with the Rune Python Generator team by creating a GitHub issue and labelling it with "help wanted".
We also encourage the community to get in touch via the FINOS Slack.
This project is governed by the FINOS Open Source Software Project Governance https://community.finos.org/docs/governance/#open-source-software-projects
Copyright 2023 CLOUDRISK Limited and FT Advisory LLC
Distributed under the Apache License, Version 2.0.
- CLOUDRISK Limited, email: info@cloudrisk.com
- FT Advisory LLC, email: info@ftadvisory.co
- TradeHeader SL, email: info@tradeheader.com
SPDX-License-Identifier: Apache-2.0