TaxBenefitSystem

class openfisca_core.taxbenefitsystems.TaxBenefitSystem(entities)[source]

Represents the legislation.

It stores parameters (values defined for everyone) and variables (values defined for some given entity e.g. a person).

parameters

Directory containing the YAML parameter files.

Parameters

entities (Sequence[Entity]) – Entities used by the tax benefit system.

add_variable(variable)[source]

Adds an OpenFisca variable to the tax and benefit system.

Parameters

variable (Variable) – The variable to add. Must be a subclass of Variable.

Raises

openfisca_core.errors.VariableNameConflictError – if a variable with the same name have previously been added to the tax and benefit system.

Return type

Variable

add_variables(*variables)[source]

Adds a list of OpenFisca Variables to the TaxBenefitSystem.

See also add_variable

add_variables_from_directory(directory)[source]

Recursively explores a directory, and adds all OpenFisca variables found there to the tax and benefit system.

add_variables_from_file(file_path)[source]

Adds all OpenFisca variables contained in a given file to the tax and benefit system.

apply_reform(reform_path)[source]

Generates a new tax and benefit system applying a reform to the tax and benefit system.

The current tax and benefit system is not mutated.

Parameters

reform_path (str) – The reform to apply. Must respect the format installed_package.sub_module.reform

Returns

A reformed tax and benefit system.

Return type

TaxBenefitSystem

Example

>>> self.apply_reform('openfisca_france.reforms.inversion_revenus')
get_package_metadata()[source]

Gets metadata relative to the country package.

Return type

Dict[str, str]

Returns

A dictionary with the country package metadata

Example

>>> tax_benefit_system.get_package_metadata()
>>> {
>>>    'location': '/path/to/dir/containing/package',
>>>    'name': 'openfisca-france',
>>>    'repository_url': 'https://github.com/openfisca/openfisca-france',
>>>    'version': '17.2.0'
>>>    }
get_parameters_at_instant(instant)[source]

Get the parameters of the legislation at a given instant

Parameters

instant (Union[str, int, Period, Instant]) – str formatted “YYYY-MM-DD” or Instant.

Return type

Optional[ParameterNodeAtInstant]

Returns

The parameters of the legislation at a given instant.

get_variable(variable_name, check_existence=False)[source]

Get a variable from the tax and benefit system.

Parameters
  • variable_name (str) – Name of the requested variable.

  • check_existence (bool) – If True, raise an error if the requested variable does not exist.

Return type

Optional[Variable]

get_variables(entity=None)[source]

Gets all variables contained in a tax and benefit system.

Parameters

entity (Optional[Entity]) – If set, returns the variable defined for the given entity.

Return type

Dict[str, Variable]

Returns

A dictionary, indexed by variable names.

load_extension(extension)[source]

Loads an extension to the tax and benefit system.

Parameters

extension (str) – The extension to load. Can be an absolute path pointing to an extension directory, or the name of an OpenFisca extension installed as a pip package.

load_parameters(path_to_yaml_dir)[source]

Loads the legislation parameter for a directory containing YAML parameters files.

Parameters

path_to_yaml_dir – Absolute path towards the YAML parameter directory.

Example:

>>> self.load_parameters('/path/to/yaml/parameters/dir')
neutralize_variable(variable_name)[source]

Neutralizes an OpenFisca variable existing in the tax and benefit system.

A neutralized variable always returns its default value when computed.

Trying to set inputs for a neutralized variable has no effect except raising a warning.

replace_variable(variable)[source]

Replaces an existing variable by a new one.

The new variable must have the same name than the replaced one.

If no variable with the given name exists in the Tax-Benefit system, no error will be raised and the new variable will be simply added.

Parameters

variable (Variable) – The variable to replace.

Return type

None

update_variable(variable)[source]

Update an existing variable in the Tax-Benefit system.

All attributes of the updated variable that are not explicitly overridden by the new variable will stay unchanged.

The new variable must have the same name than the updated one.

If no variable with the given name exists in the tax and benefit system, no error will be raised and the new variable will be simply added.

Parameters

variable (Variable) – Variable to add. Must be a subclass of Variable.

Return type

Variable

Returns

The added variable.