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 metatada relative to the country package the tax and benefit system is built from.

Returns

Country package metadata

Return type

dict

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

instantstr of the format ‘YYYY-MM-DD’ or Instant instance.

Returns

The parameters of the legislation at a given instant.

Return type

ParameterNodeAtInstant

get_variable(variable_name, check_existence=False)[source]

Get a variable from the tax and benefit system.

Parameters
  • variable_name – Name of the requested variable.

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

get_variables(entity=None)[source]

Gets all variables contained in a tax and benefit system.

Parameters

entity (Entity) – If set, returns only the variable defined for the given entity.

Returns

A dictionary, indexed by variable names.

Return type

dict

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 OpenFisca variable in the tax and benefit system 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 and benefit system, no error will be raised and the new variable will be simply added.

Parameters

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

update_variable(variable)[source]

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

All attributes of the updated variable that are not explicitely 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.