Skip to main content

OpenFisca tax and benefit system for Country-Template

Project description

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 will create your own copy of this boilerplate directory and customise 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-france.

  3. Set up the two following variables and execute the bootstrap.sh script to initialise the git repository and replace all references to openfisca_country_template with references to your new country package in the code base:

export COUNTRY_NAME=France  # set the name of your country here; you should keep all capitals, and replace any spaces in the name by underscores
export REPOSITORY_URL=https://github.com/YOUR_ORGANISATION/OpenFisca-$COUNTRY_NAME  # set here the URL of the repository you created in step 2.
./bootstrap.sh
  1. Push your changes to your git host:
git push origin master

That's it, you're all set!

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.7. 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 (in which case we recommend using ConEmu instead of the default console).

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 openfisca # create a new venv called “openfisca”
source openfisca/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.7.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.7.xx".
pip --version  # should print at least 9.0.
# if not, run "pip install --upgrade pip"

Clone this Country Package on your machine:

git clone https://github.com/openfisca/openfisca-country-template.git
cd openfisca-country-template
pip install --editable .[dev]

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

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.

Substitute your package's country name for openfisca_country_template below:

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

Project details


Release history Release notifications | RSS feed

This version

4.0.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

OpenFisca-Country-Template-4.0.0.tar.gz (32.5 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file OpenFisca-Country-Template-4.0.0.tar.gz.

File metadata

File hashes

Hashes for OpenFisca-Country-Template-4.0.0.tar.gz
Algorithm Hash digest
SHA256 df556eb708078414f17b6afebb8fd1c6d608314b19e766beb8dec1fa40b74a38
MD5 610d47e3de3fa53ea234eed98aff9c2d
BLAKE2b-256 786b05e98bdb2759b1935052fa214162dc3229e1187252b4509116ead72d6b75

See more details on using hashes here.

File details

Details for the file OpenFisca_Country_Template-4.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for OpenFisca_Country_Template-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4cd73b944a55fcab1eaf48bc77625835fd7261de08e1c89ad175d719abd2490a
MD5 9df79740024c20218eba399777b3cad1
BLAKE2b-256 c9198ecfdce3fce061b79d31ed00c1d85747d75ea8063410a6eeadcc65e1d18a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page