OpenFisca-Core
raw JSON → 44.7.0 verified Fri May 01 auth: no python
OpenFisca is a versatile microsimulation free software. This is the core engine that compiles and evaluates tax-benefit rules written in Python. Current version: 44.7.0. Released roughly monthly.
pip install openfisca-core Common errors
error ModuleNotFoundError: No module named 'openfisca_core' ↓
cause You imported 'openfisca_core' but the package is not installed or you used wrong name (e.g., 'openfisca.core').
fix
Install with: pip install openfisca-core
error AttributeError: module 'openfisca_core' has no attribute 'SimulationBuilder' ↓
cause You did a `import openfisca_core` and tried `openfisca_core.SimulationBuilder`. Symbols are in submodules.
fix
Use:
from openfisca_core.simulation_builder import SimulationBuilder error The module 'openfisca_france' is not installed. ↓
cause You tried to load a country package that is not installed.
fix
Install the correct country package, e.g., pip install openfisca-france
Warnings
breaking In version 35+ the `simulation.calculate('variable')` now returns a numpy array instead of a float. Use `.item()` for scalar. ↓
fix call `.item()` on the result for scalar values, or use indexing.
deprecated The use of `openfisca_core.tracer` (singular) is deprecated; use `openfisca_core.tracers` (plural). ↓
fix replace `from openfisca_core.tracer import Tracer` with `from openfisca_core.tracers import Tracer`
gotcha OpenFisca-Core does not include any country package. You must install a country package separately, e.g., `pip install openfisca-france`. ↓
fix install the relevant country package or define your own taxbenefitsystem.
Imports
- SimulationBuilder
from openfisca_core.simulation_builder import SimulationBuilder - Tracer wrong
from openfisca_core.tracer import Tracercorrectfrom openfisca_core.tracers import Tracer - Variable
from openfisca_core.variables import Variable
Quickstart
from openfisca_core.simulation_builder import SimulationBuilder
from openfisca_core.taxbenefitsystems import TaxBenefitSystem
# Example: load a country package (must be installed separately)
# Here using openfisca-france as an example
system = TaxBenefitSystem.load('openfisca_france')
builder = SimulationBuilder()
simulation = builder.build_from_entities(system, {'personnes': {'individus': [{}]}})
print(simulation.calculate('salaire_imposable', period='2023-01'))