Skip to main content

OpenFisca Country-Template

This repository helps you quickly bootstrap and use your own OpenFisca country package.

You should NOT fork it but download a copy of it and follow the bootstrapping instructions below.

Otherwise, you will have to clean up all tags when you deploy your own country package.

Bootstrapping your Country Package

This set of instructions only needs to be followed once and will create your own copy of this boilerplate directory, customising it to the country you want to work on. You will need to have Git installed.

  1. Download a copy of this repository, unzip it and cd into it in a Terminal window.

  2. Create a new repository on your favourite git host (Github, Bitbucket, GitLab, etc) with the name openfisca-your_country_name. For example, openfisca-new_zealand or openfisca-france.

  3. Execute the bootstrap.sh script to initialise the git repository. This performs numerous tasks including replacing all references to openfisca-country_template with references to the new country package.

    • To execute the script run bash bootstrap.sh from the command line. Note: this script can only run on Unix systems, but OpenFisca and the resulting package will work on Windows too.
    • After the bootstrap.sh has run both it and these instructions are removed.
  4. Follow the instructions in the new repository's README.md.

Writing the Legislation

The country whose law is modelled here has a very simple tax and benefit system.

  • It has a flat rate tax whose rates increase every year.
  • On the first of December, 2015, it introduced a basic income for all its citizens of age who have no income.
  • On the first of December, 2016, it removed the income condition, providing all its adult citizens with a basic income.

These elements are described in different folders. All the modelling happens within the openfisca_country_template folder.

  • The rates are in the parameters folder.
  • The formulas are in the variables folder.
  • This country package comes also with reforms in the reforms folder. This is optional: your country may exist without defining any reform.
    • In this country, there is a reform project aiming to modify the social security taxation, deleting the first bracket, raising the intermediary ones and adding a new bracket with a higher tax rate of 40 % for people earning more than 40000. This reform project would apply starting from 2017-01-01.

The files that are outside from the openfisca_country_template folder are used to set up the development environment.

Packaging your Country Package for Distribution

Country packages are python distributions. To distribute your package via pip, follow the steps given by the Python Packaging Authority.

Install Instructions for Users and Contributors

This package requires Python 3.9. More recent versions should work, but are not tested.

All platforms that can execute Python are supported, which includes GNU/Linux, macOS and Microsoft Windows.

Setting-up a Virtual Environment with venv

In order to limit dependencies conflicts, we recommend using a virtual environment with venv.

  • A venv is a project specific environment created to suit the needs of the project you are working on.

To create a virtual environment, launch a terminal on your computer, cd into your directory and follow these instructions:

python3 -m venv .venv # create a new virtual environment in the “.venv” folder, which will contain all dependencies
source .venv/bin/activate # activate the venv

You can now operate in the venv you just created.

You can deactivate that venv at any time with deactivate.

:tada: You are now ready to install this OpenFisca Country Package!

Two install procedures are available. Pick procedure A or B below depending on how you plan to use this Country Package.

A. Minimal Installation (Pip Install)

Follow this installation if you wish to:

  • run calculations on a large population;
  • create tax & benefits simulations;
  • write an extension to this legislation (e.g. city specific tax & benefits);
  • serve your Country Package with the OpenFisca Web API.

For more advanced uses, head to the Advanced Installation.

Install this Country Package with Pip Install

Inside your venv, check the prerequisites:

python --version  # should print "Python 3.9.xx".
pip --version  # should print at least 9.0.
# if not, run "pip install --upgrade pip"

Install the Country Package:

pip install openfisca-country_template

:warning: Please beware that installing the Country Package with pip is dependent on its maintainers publishing said package.

:tada: This OpenFisca Country Package is now installed and ready!

Next Steps

Depending on what you want to do with OpenFisca, you may want to install yet other packages in your venv:

B. Advanced Installation (Git Clone)

Follow this tutorial if you wish to:

  • create or change this Country Package's legislation;
  • contribute to the source code.

Clone this Country Package with Git

First, make sure Git is installed on your machine.

Set your working directory to the location where you want this OpenFisca Country Package cloned.

Inside your venv, check the prerequisites:

python --version  # should print "Python 3.9.xx".

Clone this Country Package on your machine:

git clone https://example.com/repository.git
cd repository_folder
pip install --upgrade pip build twine
pip install --editable .[dev] --upgrade

You can make sure that everything is working by running the provided tests with make test.

Learn more about tests

:tada: This OpenFisca Country Package is now installed and ready!

Next Steps

Serve this Country Package with the OpenFisca Web API

If you are considering building a web application, you can use the packaged OpenFisca Web API with your Country Package.

To serve the Openfisca Web API locally, run:

openfisca serve --port 5000 --country-package openfisca_country_template

Or use the quick-start Make command:

make serve-local

To read more about the openfisca serve command, check out its documentation.

You can make sure that your instance of the API is working by requesting:

curl "http://localhost:5000/spec"

This endpoint returns the Open API specification of your API.

:tada: This OpenFisca Country Package is now served by the OpenFisca Web API! To learn more, go to the OpenFisca Web API documentation.

You can test your new Web API by sending it example JSON data located in the situation_examples folder.

curl -X POST -H "Content-Type: application/json" \
  -d @./openfisca_country_template/situation_examples/couple.json \
  http://localhost:5000/calculate

Release files for openfisca-country_template 7.0.0

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

Source distribution (sdist)

Source distribution for openfisca-country_template 7.0.0
File Size Uploaded
openfisca_country_template-7.0.0.tar.gz 32.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for openfisca-country_template 7.0.0
File Interpreter ABI Platform
openfisca_country_template-7.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 77.1 kB

Release files / openfisca_country_template-7.0.0.tar.gz

Download URL openfisca_country_template-7.0.0.tar.gz
Size 32.9 kB
Tags Source
SHA-256 checksum
How to use checksums
75a87364f50cba3590bd1c5157c2cf194ba6e1adf939e2c8e4e4b4f5651a0d68
BLAKE2b-256 checksum
How to use checksums
8bcd29df0aadf09fb5945bddd2f19344809adbe8b3743607eaf92a7cdb6d5ef0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.9

Release files / openfisca_country_template-7.0.0-py3-none-any.whl

Download URL openfisca_country_template-7.0.0-py3-none-any.whl
Size 44.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a266c34a2654a8f1646b4140e947b81e79215397d40da2c4eba7bfce61039546
BLAKE2b-256 checksum
How to use checksums
410e455b41514aa93b5b2e7f0868bbbb721a6a1e5af0dd5b75c3337f4dc08cb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.9

Release history Release notifications | RSS feed

8.1.0

2 release files

8.0.5

2 release files

8.0.4

2 release files

8.0.3

2 release files

8.0.2

2 release files

8.0.1

2 release files

8.0.0

2 release files

7.1.9

2 release files

7.1.8

2 release files

7.1.7

2 release files

7.1.6

2 release files

7.1.5

2 release files

7.1.4

2 release files

7.1.1

2 release files

7.1.0

2 release files

This release

7.0.0 This release

2 release files

6.0.3

2 release files

6.0.2

2 release files

6.0.1

2 release files

6.0.0

2 release files

5.0.0

2 release files

4.0.0

2 release files

3.13.1

1 release file

3.13.0

1 release file

3.12.10

1 release file

3.12.9

1 release file

3.12.8

1 release file

3.12.7

1 release file

3.12.6

1 release file

3.12.5

1 release file

3.12.4

1 release file

3.12.3

1 release file

3.12.2

1 release file

3.11.0

1 release file

3.10.0

1 release file

3.9.13

1 release file

3.9.12

1 release file

3.9.11

1 release file

3.9.10

1 release file

3.9.9

1 release file

3.9.8

1 release file

3.9.7

1 release file

3.9.6

1 release file

3.9.5

1 release file

3.9.4

1 release file

3.9.3

1 release file

3.9.2

1 release file

3.9.1

1 release file

3.9.0

1 release file

3.8.0

1 release file

3.7.0

1 release file

3.6.0

2 release files

3.5.3

2 release files

3.5.2

2 release files

3.5.0

2 release files

3.4.0

2 release files

3.3.2

2 release files

3.3.1

2 release files

3.3.0

2 release files

3.2.3

2 release files

3.2.2

2 release files

3.2.1

2 release files

3.2.0

2 release files

3.1.3

2 release files

3.1.2

2 release files

3.1.1

2 release files

3.0.2

2 release files

3.0.1

1 release file

3.0.0

1 release file

2.1.0

1 release file

2.0.1

1 release file

1.4.0

1 release file

1.3.2

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.7

1 release file

1.2.6

1 release file

1.2.5

1 release file

1.2.4

1 release file

1.2.3

1 release file

1.2.2

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.0.0

1 release file

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