Skip to main content

DamlForge

Write Daml smart contracts for Canton in Python syntax.

PyPI Python License

User guide · Examples · Releases

DamlForge lets you write Canton smart contracts in .vy files. These use Python syntax with a few contract-specific (Vyper-flavored) keywords. The forge compiler turns each .vy file into ordinary Daml source, and DPM, the Daml package manager, builds, tests, and ships that source. Nothing in a .vy file runs as Python: the file is parsed, checked, and lowered straight to Daml.

How it works

1. Install DamlForge (Python 3.11 or newer):

pip install damlforge

2. Write a contract in Main.vy:

from forge.builtins.daml_lang import create
from forge.models import ContractId, Party, choice, template


@template
class Asset:
    issuer: Party
    owner: Party
    name: str

    signatory: Party = issuer
    observer: Party = owner
    ensure: bool = name != ""

    @choice(controller=owner, consuming=True)
    def give(self, new_owner: Party) -> ContractId[Asset]:
        return create(Asset(issuer=self.issuer, owner=new_owner, name=self.name))

3. Compile it to Daml:

forge daml Main.vy -o out/

forge generates out/Main.daml:

module Main where

template Asset
  with
    issuer : Party
    owner : Party
    name : Text
  where
    signatory issuer
    observer owner
    ensure name /= ""

    choice Give : ContractId Asset
      with
        new_owner : Party
      controller owner
      do
        let self = this
        create (Asset with issuer = self.issuer, owner = new_owner, name = self.name)

More: see the full documentation, from setup to packaging.

Documentation

The guide at docs.damlforge.noders.services walks through DamlForge from setup to packaging. Every example in it compiles with forge dar.

# Page Covers
1 Development Environment Setup Installing DPM and DamlForge, creating a project, editor setup, day-to-day commands
2 Language Fundamentals Types, structs, enums, variants, Optional, functions, control flow, dates, imports
3 Compiler Errors Every DF error code, with the message, cause, and fix
4 Contract Templates Templates, signatories, observers, ensure, testing with Daml Script
5 Choices Choices as methods and as delegation, updating a contract in place, consuming and non-consuming choices, a simple cash model
6 Design Patterns Propose-accept, delegation, authorization, locking, multi-party agreements
7 Working with Time datetime support, ledger time, deadlines and time windows, setTime/passTime
8 Contract Keys key and maintainer, by-key lookups, Daml 3.5 requirements
9 Interfaces Declaring and implementing interfaces, views, converting contract IDs
10 Building and Packaging forge dar, daml.yaml settings, multi-package projects, DAR contents
11 Variants Constructor styles, recursive and generic variants, current limitations

Claude Code skill

See .claude/skills/damlforge-vy-lang/ for the full language reference. It is also a Claude Code skill: Claude Code uses it to write, read, and review .vy files, translate .daml files to .vy, and explain DF compiler errors in this repository.

Installing

DamlForge is published on PyPI as damlforge. It installs the forge command and the forge Python package:

python -m venv .venv
source .venv/bin/activate          # .venv\Scripts\activate on Windows
pip install damlforge
Using DamlForge in another project (pip, Poetry)

Add DamlForge as a dependency of the project that holds your .vy contracts.

With pip, pin it in requirements.txt:

damlforge==<version>

Then install and build:

pip install -r requirements.txt
forge dar path/to/daml_project -o out.dar

With Poetry, add it to a dev group, since it's only needed at build time:

poetry add --group dev damlforge@<version>

This records it in your pyproject.toml:

[tool.poetry.group.dev.dependencies]
damlforge = { version = "<version>", extras = ["stubgen"] }

Leave out extras if you don't need forge stubs. Run the compiler through Poetry's environment:

poetry install
poetry run forge dar path/to/daml_project -o out.dar

The stubs for the Daml standard library (DA.*, GHC.*), Splice (Splice.*), forge.models, and forge.builtins ship inside the package. Once it's installed, .vy files import them directly, with no extra path setup:

from DA.List import sort
from forge.builtins.daml_lang import create
from forge.models import Party, choice, template

Splice stubs also need the matching Splice DAR in data-dependencies in daml.yaml. See Development Environment Setup and Building and Packaging.

Installing from GitHub Releases

Releases are also built by CI on every v*.*.* tag and attached to the corresponding GitHub Release as damlforge-<version>-py3-none-any.whl, which installs with pip install damlforge-<version>-py3-none-any.whl.

Upgrading

Upgrade in place:

pip install -U damlforge==<new-version>

If you installed the old forge wheel from GitHub Releases, run pip uninstall forge first, since the distribution was renamed to damlforge.

Publishing to PyPI

.github/workflows/publish-pypi.yml is started by hand from the Actions tab (Run workflow) with the version to publish. It builds the sdist and wheel with that version and uploads them through PyPI trusted publishing, so no API token is stored in the repository.

Commands

Installing the wheel puts a forge command on your PATH. It's a Click CLI with a subcommand per compile target:

forge --help          # top-level usage and subcommand list
forge --version       # installed forge version
forge daml --help     # per-subcommand usage (also: forge dar, forge json, forge stubs)
forge daml path/to/file.vy -o out/          # .vy -> out/<Module>.daml + out/<Module>.map.json
forge daml path/to/vy_source_dir -o out/    # compiles top-level .vy files in the directory
forge dar path/to/vy_project -o out.dar     # compile the project and build a real .dar
forge json path/to/file.vy --pretty-json    # .vy -> JSON AST, printed to stdout
forge stubs input.dar -o generated/         # .dar -> generated .vy stubs

forge <path> [options] (no subcommand) is shorthand for forge daml <path> [options]. forge stubs uses dazl, which is installed together with DamlForge.

See Building and Packaging for daml.yaml requirements, DPM options, and stub generation.

Examples

The examples/ directory has complete projects to compile and study:

Example Shows
examples/basic/ Templates, interfaces, cross-module imports
examples/token_standard/ A Splice token-standard holding and transfer flow
examples/splice-api-token-burn-mint-v1/ A template implementing the external Splice Holding interface
examples/crowd_loans/ Enums, GenMap, nested loops, Splice data dependencies
examples/splice-util-batched-markers/ A Splice featured-app template with structs, choices, and Splice API data dependencies
examples/splice-util-batched-markers-test/ the upstream Splice Daml Script test, run against both the generated and the original package

Every example and test package pins Daml SDK 3.5.2 (sdk-version in its daml.yaml).

How the examples are verified

CI compiles each example from its .vy sources and then runs Daml Script tests against the generated code. All Daml in this repository, generated and hand-written, is built with Daml SDK 3.5.2:

  1. scripts/fetch-splice-dars.sh downloads the pinned Splice DARs into examples/dars/ and checks them against scripts/splice-dars.sha256.
  2. forge dar examples/<name> -o examples/<name>/<name>-ci.dar compiles every .vy file to Daml and runs dpm build. The generated .daml files and DARs are git-ignored and rebuilt on every run.
  3. examples/splice-util-batched-markers-original is the hand-written Splice BatchedMarkersProxy, built with plain dpm build. The only edit is removing Serializable from deriving, which Daml 3 no longer has.
  4. Two test packages share one Daml Script source, examples/splice-util-batched-markers-test/daml. splice-util-batched-markers-test depends on the DAR generated from the .vy; splice-util-batched-markers-original-test depends on the DAR of the hand-written original. Both run the same tests, so the generated package must expose the same templates, choices and field names as the original. These tests are the only committed .daml files in examples/ besides the original; .gitignore allows examples/*-test/daml/**/*.daml and examples/*-original/daml/**/*.daml.
  5. dpm test runs the upstream Splice test Splice.Util.FeaturedApp.UnitTests.BatchedMarkersProxy, copied unchanged from daml/splice-util-batched-markers-test in Splice. It runs on the Splice Amulet test registry (Splice/Testing/**, copied unchanged from token-standard/splice-token-standard-v1-test), and exercises CreateMarkers and CreateMarkersV2 against real featured-app rights and checks the created markers.

Why the generated loops differ from the original

The two packages are not textually identical, and the tests check behaviour, not text. Daml has no mutable variables, so DamlForge turns a .vy for loop that updates an accumulator into a fold:

.vy / original Generated Daml
for batch in batches: total = total + batch.numMarkers foldl (\(total, ...) batch -> ...) (total, None) batches
loop body that calls exercise (a ledger action) foldlA, the monadic fold, so the actions run in order
range(0, n) [0 .. n - 1]; the original writes forA [1..n]
results.append(x) results <> [x], threaded through the fold; the original uses forA, which returns the list directly
assert on a sum the sum is computed by the fold first, then assertMsg; the original uses sum and require

Both forms run the same number of iterations in the same order, create the same contracts and abort on the same inputs. The shared Daml Script source checks exactly that: the marker counts and weights for both choices, and the four guards that must abort. A mismatch in an index range, the order of results, or an assertion would fail one package and not the other.

Run the whole loop locally with make test-examples, after dpm install package in each example directory. The examples-build job in .github/workflows/tests.yml does the same on every push.

Building the wheel yourself

If you have the source checked out:

pip install build
python -m build          # or: make build

produces dist/damlforge-<version>-py3-none-any.whl, versioned from the nearest git tag (see Makefile's build/release targets and .github/workflows/build-wheel.yml).

Local development

python -m venv .venv
source .venv/bin/activate
pip install -e .              # installs forge + runtime deps (click, etc.) in editable mode
pip install --group test      # pytest + friends
pip install --group lint      # black/flake8/isort/mypy

--group needs pip>=25.1 (pip install -U pip first if needed); otherwise install the pinned packages listed under [dependency-groups] in pyproject.toml directly.

With an editable install, forge/python -m forge picks up changes under forge/ immediately - no reinstall needed:

forge --help
forge daml examples/basic/simple.vy -o /tmp/out && cat /tmp/out/Simple*.daml

Run the test suite and linters:

pytest -q      # or: make test
make lint      # mypy, black, flake8, isort in sequence

License

DamlForge is licensed under the Apache License, Version 2.0.

Copyright 2026 Noders Team. Author: Artem Bogomaz artembogomaz@gmail.com.

Metadata

Release files for damlforge 0.0.16

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for damlforge 0.0.16
File Size Uploaded Provenance Actions
damlforge-0.0.16.tar.gz 430.5 kB With provenance Details for damlforge-0.0.16.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for damlforge 0.0.16
File Interpreter ABI Platform Actions
damlforge-0.0.16-py3-none-any.whl Python 3 none any Details for damlforge-0.0.16-py3-none-any.whl

Total release size: 747.0 kB

Release files / damlforge-0.0.16.tar.gz

Download URL damlforge-0.0.16.tar.gz
Size 430.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f5c7199f0f4faf113a136af494174c0da84aaeabac877103f17c09aa0122b0df
BLAKE2b-256 checksum
How to use checksums
61771cd962820294007c96b4310ff795354382631216e9cb247276f52760f2cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Release files / damlforge-0.0.16-py3-none-any.whl

Download URL damlforge-0.0.16-py3-none-any.whl
Size 316.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac424a740263e8127b522610cdf27366981335a209e2803c3ccb5bdb17dd5823
BLAKE2b-256 checksum
How to use checksums
ec8a4cd32c8a4e462bb0723aed60fa7549aa96daf2914750efa560fe80d749f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

Security for damlforge 0.0.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for damlforge-0.0.16.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page