• Stars
    star
    168
  • Rank 225,507 (Top 5 %)
  • Language
    Python
  • License
    GNU Affero Genera...
  • Created almost 11 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

OpenFisca core engine. See other repositories for countries-specific code & data.

OpenFisca Core

PyPi Downloads PyPi Version Conda Downloads Conda Version

Python Coveralls Contributors

Newsletter Twitter Slack

OpenFisca is a versatile microsimulation free software. Check the online documentation for more details.

This package contains the core features of OpenFisca, which are meant to be used by country packages such as OpenFisca-France. Bootstrapping your own country package should not take more than 5 minutes: check our country package template.

Environment

OpenFisca runs on Python 3.7. More recent versions should work but are not tested.

OpenFisca also relies strongly on NumPy. The last four minor versions should work, but only the latest/stable is tested.

Installation

If you're developing your own country package, you don't need to explicitly install OpenFisca-Core. It just needs to appear in your package dependencies. If you want to contribute to OpenFisca-Core itself, welcome! To install it locally you can use one of these two options:

  • conda package manager that we recommend for Windows operating system users,
  • or standard Python pip package manager.

Installing openfisca-core with pip

This installation requires Python 3.7+ and GIT installations.

To install openfisca-core locally in development mode run the following commands in a shell terminal:

git clone https://github.com/openfisca/openfisca-core.git
cd openfisca-core
python3 -m venv .venv
source .venv/bin/activate
make install-deps install-edit

Installing openfisca-core with conda

Since openfisca-core version 35.7.7, you could use conda to install OpenFisca-Core.

Conda is the easiest way to use OpenFisca under Windows as by installing Anaconda you will get:

If you are familiar with the command line you could use Miniconda, which needs very much less disk space than Anaconda.

After installing conda, run these commands in an Anaconda Powershell Prompt:

  • conda create --name openfisca python=3.7 to create an openfisca environment.
  • conda activate openfisca to use your new environment.

Then, choose one of the following options according to your use case:

  • conda install -c conda-forge openfisca-core for default dependencies,
  • or conda install -c conda-forge openfisca-core-api if you want the Web API part,
  • or conda install -c conda-forge -c openfisca openfisca-core-dev if you want all the dependencies needed to contribute to the project.

For information on how we publish to conda-forge, see openfisca-core-feedstock.

Testing

Install the test dependencies:

make install-deps install-edit install-test

For integration testing purposes, openfisca-core relies on country-template and extension-template. Because these packages rely at the same time on openfisca-core, they need to be installed separately.

To run the entire test suite:

make test

To run all the tests defined on a test file:

pytest tests/core/test_parameters.py

To run a single test:

pytest tests/core/test_parameters.py -k test_parameter_for_period

Types

This repository relies on MyPy for optional dynamic & static type checking.

As NumPy introduced the typing module in 1.20.0, to ensure type hints do not break the code at runtime, we run the checker against the last four minor NumPy versions.

Type checking is already run with make test. To run the type checker alone:

make check-types

Style

This repository adheres to a certain coding style, and we invite you to follow it for your contributions to be integrated promptly.

Style checking is already run with make test. To run the style checker alone:

make check-style

To automatically style-format your code changes:

make format-style

To automatically style-format your code changes each time you commit:

touch .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

tee -a .git/hooks/pre-commit << END
#!/bin/sh
#
# Automatically format your code before committing.
exec make format-style
END

Documentation

OpenFisca鈥檚 toolchain checks whether documentation builds correctly and updates it automatically with each contribution to this repository.

In the meantime, please take a look at our contributing guidelines for some general tips on how to document your contributions, and at our official documentation's repository to in case you want to know how to build it by yourself 鈥攁nd improve it!

Serving the API

OpenFisca-Core provides a Web-API. It is by default served on the 5000 port.

To run it with the mock country package openfisca_country_template and another port value such as 2000, run:

openfisca serve --country-package openfisca_country_template --port 2000

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

By default, the Web API uses 3 workers to avoid this issue. Without it, AJAX requests from Chrome sometimes take more than 20s to process. You can change the number of workers by specifying a --workers k option.

You can test that the API is running by executing the command:

curl http://localhost:2000/parameters

For more information about endpoints and input formatting, see the official documentation.

Tracker

The OpenFisca Web API comes with an optional tracker which allows you to measure the usage of the API.

Tracker installation

The tracker is not installed by default. To install it, run:

pip install openfisca_core[tracker] --use-deprecated=legacy-resolver # Or `pip install --editable ".[tracker]"` for an editable installation

Tracker configuration

The tracker is activated when these two options are set:

  • --tracker-url: An URL ending with piwik.php. It defines the Piwik instance that will receive the tracking information. To use the main OpenFisca Piwik instance, use https://stats.data.gouv.fr/piwik.php.
  • --tracker-idsite: An integer. It defines the identifier of the tracked site on your Piwik instance. To use the main OpenFisca piwik instance, use 4.
  • --tracker-token: A string. It defines the Piwik API Authentification token to differentiate API calls based on the user IP. Otherwise, all API calls will seem to come from your server. The Piwik API Authentification token can be found in your Piwik interface when you are logged in.

For instance, to run the Web API with the mock country package openfisca_country_template and the tracker activated, run:

openfisca serve --country-package openfisca_country_template --port 5000 --tracker-url https://stats.data.gouv.fr/piwik.php --tracker-idsite 4 --tracker-token $TRACKER_TOKEN

More Repositories

1

openfisca-france

French tax and benefit system for OpenFisca
Python
254
star
2

calculette-impots-m-source-code

ATTENTION ce d茅p么t est un miroir
MATLAB
35
star
3

country-template

Start modelling the tax and benefit system of your country in a few minutes.
Python
31
star
4

legislation-explorer

Explore legislation formulas and parameters.
JavaScript
26
star
5

openfisca-doc

User guide of OpenFisca
CSS
18
star
6

openfisca-tunisia

Tunisian tax and benefit system for OpenFisca
Python
15
star
7

tutorial

OpenFisca Tutorial Notebooks
Jupyter Notebook
13
star
8

openfisca-web-api

[DEPRECATED] Web API for OpenFisca
Python
13
star
9

openfisca-france-data

France-Data module of OpenFisca
Python
13
star
10

openfisca.org

The public-facing website of OpenFisca for an international audience.
HTML
9
star
11

calculette-impots-python

Traduction en langage Python du code source (en langage M) du calculateur des imp么ts sur le revenu et sur la fortune
Python
9
star
12

openfisca-survey-manager

A tool for managing survey data
Python
8
star
13

openfisca-italy

Italian tax and benefit system for OpenFisca.
Python
8
star
14

openfisca-paris

Extension OpenFisca pour les prestations de la ville de Paris.
Python
7
star
15

openfisca-senegal

Senegalese tax and benefit system for OpenFisca
Jupyter Notebook
6
star
16

openfisca-france-indirect-taxation

French indirect taxation module for OpenFisca
Jupyter Notebook
5
star
17

calculette-impots-m-language-parser

Traducteur en arbre syntaxique (AST) du code source (en langage M) du calculateur des imp么ts sur le revenu et sur la fortune
Python
4
star
18

biryani

A data conversion and validation toolbox
Python
4
star
19

openfisca-france-fiscalite-miniere

French mining tax system for OpenFisca
Python
3
star
20

openfisca-france-local

Extension OpenFisca pour nos partenariats avec les collectivit茅s territoriales
Python
3
star
21

openfisca-web-ui-legacy

[DEPRECATED] See
JavaScript
3
star
22

openfisca-events

History of produced OpenFisca code in hackathons and other events.
Jupyter Notebook
2
star
23

combine-calculators

Use OpenFisca with other calculators, compare results, merge their formulas
MATLAB
2
star
24

openfisca-parsers

[DEPRECATED] Lexers, parsers, compilers, etc for OpenFisca source code
Python
2
star
25

openfisca-mali

Malian tax and benefit system for OpenFisca
Python
2
star
26

openfisca-matplotlib

Python
2
star
27

openfisca-cote-d-ivoire

Ivorian tax and benefit system for OpenFisca
Python
2
star
28

fr.openfisca.org

Le site web d'OpenFisca-France. / OpenFisca-France web site.
JavaScript
2
star
29

openfisca-ops

Scripts and config files for deploying OpenFisca on a server
Jinja
1
star
30

openfisca-web-site

[DEPRECATED] OpenFisca web site
Mako
1
star
31

openfisca-france-extension-revenu-de-base

R茅forme du revenu de base pour OpenFisca
Python
1
star
32

openfisca-douanes

Simulateur ouvert de taxes de douanes - en d茅veloppement
Python
1
star
33

openfisca-brestmetropole

Extension OpenFisca pour Brest m茅tropole
Python
1
star
34

reform-simulator

UI to simply and quickly simulate the impact of tax-benefit reforms on indivuduals
Python
1
star
35

openfisca-plugin-aggregates

A plugin that adds aggregates handling to OpenFisca
Python
1
star
36

OpenFiscaFrance.jl

A port of OpenFisca-France to Julia. This is the OpenFisca package containing the formulas and parameters of the french tax-benefit system.
Julia
1
star
37

calculette-impots-web-explorer

Explorateur web des variables et formules du calculateur des imp么ts sur le revenu et sur la fortune
Python
1
star
38

tracer

A basic tool to investigate OpenFisca computations
CSS
1
star
39

openfisca-dummy-country

[DEPRECATED] A fake country package used by OpenFisca for tests
Python
1
star
40

openfisca-france-inheritance

French inheritance legislation specific model for OpenFisca
Python
1
star
41

support-bot

This smalls bot helps the OpenFisca team remember users are waiting for their help!
JavaScript
1
star
42

communication

Communication material for the OpenFisca project
JavaScript
1
star
43

calculette-impots-web-api

API web (茅crite en Python) du calculateur des imp么ts sur le revenu et sur la fortune
Python
1
star
44

openfisca-france-pension

French Pension Schemes for OpenFisca
Python
1
star
45

tracker

OpenFisca Web API usage tracker
Python
1
star