Introduction to OpenFisca

GovCMS Rules as Code series

Date:
21 May 2025

Don’t forget to subscribe to our YouTube channelExternal Link to stay up-to-date.

Introduction to OpenFisca

This video covers an introduction to OpenFisca, covering the five stages of OpenFisca development: write test cases, create entities, create parameters, create input variables and create formula (output variables).

Video sections

0:00 – 1:06 - Introduction

1:07 – 2:23 - Solution architecture, OpenFisca and Drupal

2:24 – 2:44 - Write test scenarios

2:45 – 3:04 - Create entities

3:05 – 3:45 - Create parameters
.
3:46-4:07 – Create input variables

4:08 - 4:40 - Create formula (output variables)

4:41 - 4:54 - Closing

GovCMSExternal Link

OpenFiscaExternal Link

DrupalExternal Link

Transcript

Hi, and welcome to the fourth video in our five-part series about Rules as Code. My name is Phillipa Martin, and I'm the Rules as Code lead at Salsa Digital, an open-source digital innovation company based in Melbourne, Australia. Today I'm here to talk to you about Rules as Code or RaC for short on behalf of GovCMS. GovCMS is a whole-of-government content management system and web hosting platform built by government for government.

First of all, a quick introduction. With a background in content and an interest in the law, I started in Rules as Code in January 2022, working with a larger project team to convert the New Zealand Social Security Act into an interactive rules as code experience for New Zealand citizens. Since then, I've continued working in the Rules as Code space as a business analyst, analysing and mapping legislation and other rules while also focusing on user journeys. In the last video, you learned about rules mapping. In this fourth video in our Rules as Code series, we focus on the next step in our process coding the legislation in OpenFisca.

But first, let's take a high-level look at the solution architecture we use. Looking at this diagram, you can see that we start with legislation on the bottom right, which then gets coded into OpenFisca. From there, the OpenFisca API integrates with Drupal and GovCMS. We cover the Drupal part of this solution in our fifth and final video. Users interact with the rules via different user experiences such as websites, mobile apps, and voice devices. Before we look at OpenFisca, I do want to address one issue that we often get asked about. Why OpenFisca and not Drupal? While we could have used Drupal to code the logic by creating a custom module, it's a square peg into a round hole. Drupal is not built for rules coding and complex logic. Drupal is built for content modelling and management, and it's one of the best in the CMS space. On the other hand, OpenFisca is the most widely adopted free and open-source engine to write Rules as Code. The way OpenFisca is programmed, it makes the process faster and more efficient for our purposes. OpenFisca is a lightweight, modular, and scalable Python-based rules engine. OpenFisca was initially developed by the French Government in 2011 to codify the French social security benefits.

When creating the rules in OpenFisca, we follow a test-driven development approach. So we start with the test scenarios. This screenshot shows a test case for the sole parent support entitlement in BenefitMe. It shows inputs that would give an output of entitled. The OpenFisca framework has a concept of entities and the rules can be defined for different kinds of entities like person, household, companies etc. In this BenefitMe screenshot we see the family entity. You may remember in our last video we looked at rules mapping and the entity was a person.

The next step is to define parameters. The parameters have a description, reference and values. The important thing to note here is that values is an array and the key to the array is a date value. This is really important because using this we can actually define the parameter value for a different period. The period can be date, week, year and so on based on the requirement. In this case it is date. This helps greatly with revisioning or versioning of the rules. We can create a new rule that will come into effect on a certain date. Then OpenFisca keeps the historical rules and values plus the current ones and you can set up future ones too.

The next step is to define the variables. The variables can be input variables or output variables. And the variable attributes are value type, entity, definition period, label, and reference. On-screen you can see a couple of different input variables as well. Remember in the last slide I mentioned output variables. So we need to define the output variables but the values for these is actually a formula. The formula will take the parameters defined and the input variables and calculate the output. Please note that they also have a definition period that can be versioned. On-screen we see the formula output variables for sole parent support equals entitled with the attributes of value type, entity, definition period, label and reference.

Thanks for listening to this fourth video in our Rules as Code series. In our next and final video, we'll look at how we use Drupal to deliver rules as code at Salsa Digital and GovCMS. Thank you.