Skip to main content

A versatile microsimulation free software

Project description

OpenFisca Core

Newsletter Twitter Slack

Coveralls Python PyPi

Conda-forge release info : Conda Downloads Conda Version

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. Last four minor versions should work, but only 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
pip install -U pip
pip install --editable .[dev] --use-deprecated=legacy-resolver

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 command line you could use Miniconda, wich need 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 informations on how we publish to conda-forge, see openfisca-core-feedstock.

Testing

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

Yet however OpenFisca does not follow a common convention for docstrings, our current toolchain allows to check whether documentation builds correctly and to update 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!

To verify that the documentation still builds correctly

You can run:

make test-doc

If it doesn't, or if the doc is already broken.

Here's how you can fix it:

  1. Clone the documentation, if not yet done:
make test-doc-checkout
  1. Install the documentation's dependencies, if not yet done:
make test-doc-install
  1. Create a branch, both in core and in the doc, to correct the problems:
git checkout -b fix-doc
sh -c "cd doc && git checkout -b `git branch --show-current`"
  1. Fix the offending problems —they could be in core, in the doc, or in both.

You can test-drive your fixes by checking that each change works as expected:

make test-doc-build branch=`git branch --show-current`
  1. Commit at each step, so you don't accidentally lose your progress:
git add -A && git commit -m "Fix outdated argument for Entity"
sh -c "cd doc && git add -A && git commit -m \"Fix outdated argument for Entity\""
  1. Once you're done, push your changes and cleanup:
git push origin `git branch --show-current`
sh -c "cd doc && git push origin `git branch --show-current`"
rm -rf doc
  1. Finally, open a pull request both in core and in the doc.

Continuous integration will automatically try to build the documentation from the same branch in both core and the doc (in our example "fix-doc") so we can integrate first our changes to Core, and then our changes to the doc.

If no changes were needed to the doc, then your changes to core will be verified against the production version of the doc.

If your changes concern only the doc, please take a look at the doc's README.

That's 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.

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

OpenFisca-Core-35.8.4.tar.gz (148.9 kB view details)

Uploaded Source

Built Distribution

OpenFisca_Core-35.8.4-py3-none-any.whl (207.0 kB view details)

Uploaded Python 3

File details

Details for the file OpenFisca-Core-35.8.4.tar.gz.

File metadata

  • Download URL: OpenFisca-Core-35.8.4.tar.gz
  • Upload date:
  • Size: 148.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.12

File hashes

Hashes for OpenFisca-Core-35.8.4.tar.gz
Algorithm Hash digest
SHA256 ba20edad21b30efbc5d2803847d7a4e2a5f4ff484a5ea5f97140661b38f627ce
MD5 d2ca09abafd190ac75b0d26696772779
BLAKE2b-256 d84b6d426a33b6861bcaacc0f6ebfb5dcc6d662c70c39652189644a6a09262d0

See more details on using hashes here.

File details

Details for the file OpenFisca_Core-35.8.4-py3-none-any.whl.

File metadata

File hashes

Hashes for OpenFisca_Core-35.8.4-py3-none-any.whl
Algorithm Hash digest
SHA256 464dd14b9ac1e1a085c03691c964fa2c7157d3cef09d30801328e5cb68bb893c
MD5 09f97cd793f8d46606444e3578b3dcff
BLAKE2b-256 92f6b20d8a4da853972dfefa1297fea824cdbd2bf4f68907d4a24226bbda4921

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