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.
OpenFisca runs on Python. See pyproject.toml for supported versions.
OpenFisca also relies strongly on NumPy. The last four minor versions should work, but only the latest/stable is tested.
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 we recommend to use uv.
This installation requires Python 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
uv run make testFor integration testing purposes,
openfisca-corerelies on country-template and extension-template. Because these packages rely at the same time onopenfisca-core, they need to be installed separately.
To run the entire test suite:
uv run make testIf you have many tests, you could run them in parallel :
uv run make test-core openfisca_args="--in-parallel"You could add an option --num-workers=4 to limit to 4 threads. Default is your CPU Core number minus 1.
Be aware that this add overhead so use it only for huge test suite.
To run all the tests defined on a test file:
uv run pytest tests/core/test_parameters.pyTo run a single test:
uv run pytest tests/core/test_parameters.py -k test_parameter_for_periodThis 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:
uv run make check-typesThis 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:
uv run make check-styleTo automatically style-format your code changes:
uv run make format-styleTo 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/bash
#
# Automatically format your code before committing.
# Change .venv/bin/activate if your virtual environment is located elsewhere.
source .venv/bin/activate
exec make format-style
exec make check-style
ENDOpenFisca’s 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 —and improve it!
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 2000To 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/parametersFor more information about endpoints and input formatting, see the official documentation.