A versatile microsimulation free software
Project description
OpenFisca Core
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. See setup.py for supported versions.
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 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:
- Python
- The package manager Anaconda.org
- A virtual environment manager : conda
- A GUI Anaconda Navigator if you choose to install the full Anaconda
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.11to create anopenfiscaenvironment.conda activate openfiscato use your new environment.
Then, choose one of the following options according to your use case:
conda install -c conda-forge openfisca-corefor default dependencies,- or
conda install -c conda-forge openfisca-core-apiif you want the Web API part, - or
conda install -c conda-forge -c openfisca openfisca-core-devif 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-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:
make test
If you have many tests, you could run them in parallel :
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:
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/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
END
Documentation
OpenFisca’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!
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 withpiwik.php. It defines the Piwik instance that will receive the tracking information. To use the main OpenFisca Piwik instance, usehttps://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, use4.--tracker-token: A string. It defines the Piwik API Authentication token to differentiate API calls based on the user IP. Otherwise, all API calls will seem to come from your server. The Piwik API Authentication 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openfisca_core-44.2.1.tar.gz.
File metadata
- Download URL: openfisca_core-44.2.1.tar.gz
- Upload date:
- Size: 207.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d487d864201702eb52ce4bab70ae001b2a9b5acb13bdec59fc574006ee64174e
|
|
| MD5 |
b336d7371eec93e924ac4a66b29b834a
|
|
| BLAKE2b-256 |
0a396a1822ec25b3738ba893d5ce7156ddb312643343c5a8f1e60fdca9fe4396
|
File details
Details for the file openfisca_core-44.2.1-py3-none-any.whl.
File metadata
- Download URL: openfisca_core-44.2.1-py3-none-any.whl
- Upload date:
- Size: 268.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c3e094423ceccc15f470f742aa24f36cdb9260de8ac4812d749ef0e8133b976
|
|
| MD5 |
7a4aad4c11a9ac24cca038cac88e0cfe
|
|
| BLAKE2b-256 |
7b0f8fe42f3d028090f3d1fc288a8d6f96ba67561218f4abc6538af93c76b017
|