ccnl_engine.repository¶
The knowledge port of the engine. A PayrollEngine reads every CCNL, tax
year, surtax table, capability catalog and limitation through a
KnowledgeRepository; BundledKnowledgeRepository is the one the package
ships. To add a CCNL variant or a year the bundle does not hold, pass a
repository of your own, typically one that wraps the bundled repository and
overrides the loaders it changes:
from ccnl_engine import PayrollEngine
from ccnl_engine.repository import BundledKnowledgeRepository, YearRules
class WithMyYear(BundledKnowledgeRepository):
def load_year_rules(self, year, sector, num_employees) -> YearRules:
return super().load_year_rules(year, sector, num_employees)
engine = PayrollEngine(repository=WithMyYear())
Below the facade every service receives the repository it is given: none
falls back to the bundled data, so a run never mixes two sources. The
models the port returns are frozen; build a variant with
model_copy(update=...).
ccnl_engine.repository.KnowledgeRepository
¶
Bases: Protocol
Read-only access to the versioned payroll rule bundle.
The engine depends on this interface, not on any concrete loader.
:class:~ccnl_engine.period.repositories.BundledKnowledgeRepository is the
production implementation that reads
from the package-bundled JSON files.
A CCNL is named by its slug (e.g. "metalmeccanico-federmeccanica");
the engine resolves a CNEL code to a slug through
:meth:load_contracts.
bundle_version
property
¶
Version of the rule bundle, stamped on every result.
load_contracts()
¶
Load and return the summary of every CCNL, sorted by ccnl_id.
load_ccnl(ccnl_id)
¶
Load and return the CCNL with slug ccnl_id.
load_year_rules(year, sector, num_employees)
¶
Load and return the tax year rules for year, sector, num_employees.
load_surtax_rules(year)
¶
Load and return the surtax rules for year, or None when unavailable.
load_capability_catalog(year)
¶
Load and return the capability catalog for year.
load_engine_limitations()
¶
Load and return the limitations of the engine's shared code paths.
load_variable_pay_rules(year)
¶
Load and return the statutory variable-pay rules for year.
load_family_deduction_rules(year)
¶
Load and return the Art. 12 TUIR family deduction rules for year.
load_sick_pay_rates()
¶
Load and return the INPS sickness indemnity rules.
load_insured_absence_rates()
¶
Load and return the maternity and work-injury indemnities.
load_national_holidays()
¶
Load and return the national holidays with civil effects.
ccnl_engine.repository.BundledKnowledgeRepository
¶
Production implementation of the knowledge repository port.
Satisfies :class:~ccnl_engine.period.ports.KnowledgeRepository. Reads from the
versioned JSON files bundled inside
the ccnl_engine package. All loader functions are cached, so repeated
calls for the same arguments return the same (immutable) object without
re-parsing.
bundle_version
property
¶
Version of the package-bundled datasets.
load_contracts()
¶
Return the summary of every bundled CCNL, sorted by ccnl_id.
Returns:
| Type | Description |
|---|---|
tuple[ContractSummary, ...]
|
One summary per bundled CCNL, with its readiness tier. |
load_ccnl(ccnl_id)
¶
Return the CCNL with slug ccnl_id from the bundled data files.
Returns:
| Type | Description |
|---|---|
CCNL
|
The validated, immutable CCNL. |
load_year_rules(year, sector, num_employees)
¶
load_surtax_rules(year)
¶
Return surtax rules for year.
Returns:
| Name | Type | Description |
|---|---|---|
A |
SurtaxRules
|
class: |
SurtaxRules
|
with regionale and comunale rate tables. |
load_capability_catalog(year)
¶
Return the capability catalog for year.
Returns:
| Name | Type | Description |
|---|---|---|
A |
CapabilityCatalog
|
class: |
CapabilityCatalog
|
with all declared capabilities for the requested year. |
load_engine_limitations()
¶
Return the limitations of the engine's shared code paths.
Returns:
| Type | Description |
|---|---|
tuple[ModelLimitation, ...]
|
The engine limitations of the bundle, in file order. |
load_variable_pay_rules(year)
¶
Return the statutory variable-pay rules for year.
Returns:
| Name | Type | Description |
|---|---|---|
A |
VariablePayRules
|
class: |
VariablePayRules
|
with fringe thresholds, PdR and L. 199/2025 regimes. |
load_family_deduction_rules(year)
¶
Return the Art. 12 TUIR family deduction rules for year.
Returns:
| Name | Type | Description |
|---|---|---|
A |
FamilyDeductionRules
|
class: |
load_sick_pay_rates()
¶
Return the INPS sickness indemnity rules.
Returns:
| Type | Description |
|---|---|
InpsSickPayRates
|
The waiting period, bands, annual maximum and coverage rules. |
load_insured_absence_rates()
¶
Return the maternity and work-injury indemnities.
Returns:
| Type | Description |
|---|---|
InsuredAbsenceRates
|
The INPS maternity indemnity and the work-injury measures. |
load_national_holidays()
¶
Return the national holidays with civil effects.
Returns:
| Type | Description |
|---|---|
NationalHolidays
|
The holidays of L. 260/1949 as amended, besides the Sundays. |
ccnl_engine.repository.PolicyResolver
¶
Data-driven resolver backed by the bundled Italian policy ruleset.
Rules are indexed by pay-item kind. :meth:resolve walks the list for
the matched kind in order and returns the first rule whose effective date
range contains context.as_of.
resolve(kind, context)
¶
Return the first rule matching kind and context.as_of, or None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
str
|
Pay-item kind string (e.g. |
required |
context
|
PolicyContext
|
Resolver context providing the reference date and facts. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
A |
PolicyResolution | None
|
class: |
PolicyResolution | None
|
kind on |
ccnl_engine.repository.bundled_policies()
cached
¶
Return the pay-item policy resolver of the bundled Italian ruleset.
Returns:
| Type | Description |
|---|---|
PolicyResolver
|
A freshly loaded :class: |
ccnl_engine.repository.CCNL
¶
Bases: BaseModel
Root model for a CCNL data file.
Attributes:
| Name | Type | Description |
|---|---|---|
schema_version |
Literal['0.6']
|
Data file format version (semver string). |
ruleset |
RulesetIdentity | None
|
Identity and provenance of this contract ruleset (id, version, validity, source hash, verification status). |
meta |
CCNLMeta
|
Identifying metadata — name, sector, INPS classification, sources. |
parameters |
CCNLParameters
|
Contract-wide parameters (hourly divisor, additional months, seniority-increment rules, employer funds). |
levels |
tuple[Level, ...]
|
Ordered list of classification levels from lowest to highest pay. |
apprenticeship |
tuple[ApprenticeshipTrack, ...]
|
Apprenticeship tracks modelled for this CCNL. Empty when apprenticeship is out of scope or not yet modelled. |
dual_apprenticeship |
tuple[DualTrack, ...]
|
Pay of the first- and third-level apprentices (D.Lgs. 81/2015 artt. 43 and 45); empty when not modelled. |
coverage |
CCNLCoverage
|
Notes on what the data file models; capability coverage derives from the capability registry and these notes. |
verification |
CCNLVerification
|
Human-review confidence and traceability metadata. |
work_rules |
CCNLWorkRules | None
|
Work-rules data (overtime, leave, sickness, absence). |
entry_pay |
EntryPay | None
|
The entry pay a permanent hire may take
( |
limitations
property
¶
Limitations the simplification notes declare, in note order.
level_by_code(level_code)
¶
Return the level with the given code, or raise ValueError.
Returns:
| Type | Description |
|---|---|
Level
|
The Level matching the given code. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no level with the given code exists. |
apprenticeship_tracks_for(level_code)
¶
Return every apprenticeship track whose destinations include a level.
Returns:
| Type | Description |
|---|---|
list[ApprenticeshipTrack]
|
List of ApprenticeshipTrack objects that cover the given level code. |
apprenticeship_track_named(name)
¶
Return the apprenticeship track with the given name or raise ValueError.
Returns:
| Type | Description |
|---|---|
ApprenticeshipTrack
|
The ApprenticeshipTrack with the given name. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no track with the given name exists. |
ccnl_engine.repository.YearRules
¶
Bases: BaseModel
All statutory tax and contribution parameters for a single fiscal year.
inps and apprentice are set for standard sectors; None for
domestic sectors where domestic_contributions carries the flat-rate
table instead. Exactly one contribution model is present (enforced by
the loader, which mirrors YearRulesRaw._check_contribution_model).
tfr_revaluation holds the revaluation of the TFR fund at 31
December of the year, None when the bundle has no rules for it;
tfr_settlement the separate taxation of the TFR paid on a
termination in the year, None likewise.
somma_esente comes from the year file shared by every sector and
carries the identity of that file. sector is the INPS sector of the
files, which selects how INPS charges the contribution; None for
rules built outside the loader.
ccnl_engine.repository.SurtaxRules
¶
Bases: BaseModel
Bundled addizionale regionale and comunale rates for one fiscal year.
Loaded via :func:~ccnl_engine.surtax.loaders.load_surtax_rules.
Attributes:
| Name | Type | Description |
|---|---|---|
year |
int
|
Fiscal year these rates apply to. |
regional_ruleset |
RulesetIdentity | None
|
Identity of the |
municipal_ruleset |
RulesetIdentity | None
|
Identity of the |
regionale |
dict[str, RegionaleEntry]
|
Per-region surtax data, keyed by Italian region name
(e.g. |
comunale |
dict[str, ComunaleEntry]
|
Per-municipality surtax data, keyed by codice catastale
(e.g. |
regional_provenance |
RuleProvenance | None
|
Source and status of the regional table. |
municipal_provenance |
RuleProvenance | None
|
Source and status of the municipal table. |
comunale_rates_are_advance = False
class-attribute
instance-attribute
¶
True when comunale rates are from a prior year (advance only).
comunale_advance_fraction = Decimal('0.30')
class-attribute
instance-attribute
¶
Fraction of the bracket sum used as the current-year advance.
comunale_next = Field(default_factory=dict)
class-attribute
instance-attribute
¶
Rows of the next year's municipal table resolved for that year: their rate and threshold set the acconto of the next year (D.Lgs. 360/1998 art. 1 c. 4, delibera published by 20 December).
ccnl_engine.repository.VariablePayRules
¶
Bases: BaseModel
Container for all statutory variable-pay rules for a fiscal year.
Attributes:
| Name | Type | Description |
|---|---|---|
year |
int
|
Fiscal year these rules apply to. |
fringe_benefit |
FringeBenefitRules
|
Fringe-benefit exemption thresholds. |
pdr |
PdRRules
|
Premio di risultato flat-tax parameters. |
rinnovo |
PreferentialTaxRegime
|
Contract-renewal substitute-tax regime (L. 199/2025 art. 1 c. 7): increments paid in 2026 under renewals signed within its signing window. |
notte_festivi_turni |
PreferentialTaxRegime
|
Substitute-tax regime for night, holiday and rest-day, and shift supplements (L. 199/2025 art. 1 cc. 10-11). |
travel_allowance |
TravelAllowanceRules
|
Exempt daily caps of the travel allowance (art. 51 c. 5 TUIR). |
ruleset |
RulesetIdentity | None
|
Provenance of the statutory source. |
ccnl_engine.repository.FamilyDeductionRules
¶
Bases: BaseModel
Art. 12 TUIR family deduction parameters for one tax year.
ratio_decimals is the number of decimals every ratio of the
formulas is taken to, discarding the rest (art. 12 c. 4).
ccnl_engine.repository.InpsSickPayRates
¶
Bases: BaseModel
Statutory INPS sick-pay indemnity rates (malattia ordinaria).
INPS does not cover the first carenza_days days; from the next one
the bands give the INPS rate of successive day ranges.
Bands must be ordered by day_from and must not overlap. The first
band must start at carenza_days + 1. Every statutory field is
required: the carenza, the bands, the annual maximum and the coverage
rules have no default, so an incomplete table is rejected instead of
taking a legal value it does not state.
Attributes:
| Name | Type | Description |
|---|---|---|
carenza_days |
int
|
Number of waiting days before INPS indemnity starts. |
bands |
list[SickPayBand]
|
Rate bands ordered by |
annual_max_days |
int
|
Days INPS indemnifies at most in a calendar year. |
coverage |
tuple[SickPayCoverage, ...]
|
Which workers INPS pays the indemnity to, first match wins; a worker no rule matches is not known to be covered. |
ruleset |
RulesetIdentity | None
|
Provenance of the statutory source. |
bands_provenance |
RuleProvenance | None
|
Provenance record of the indemnity rates. |
regimes |
tuple[SickPayRegime, ...]
|
Bands of the groups of workers whose rates differ from
|
fixed_term |
FixedTermSickLimit | None
|
Limit of a fixed-term contract; |
min_daily_contributions |
int | None
|
Requirement of the regime the table was
resolved for (:meth: |
for_regime(regime)
¶
Return the table with the bands of regime in place of the rule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
regime
|
str | None
|
Id of a regime of :attr: |
required |
Returns:
| Type | Description |
|---|---|
InpsSickPayRates
|
This table for |
InpsSickPayRates
|
their provenance and its fixed-term rule. |
Raises:
| Type | Description |
|---|---|
KeyError
|
When no regime has the id |
covers(sector, category, contract_type, ccnl=None)
¶
Return whether INPS pays the sickness indemnity to the worker.
Returns:
| Type | Description |
|---|---|
bool | None
|
The |
bool | None
|
no rule matches. |
band_rate(day)
¶
Return the INPS rate of episode day day.
Returns:
| Type | Description |
|---|---|
Decimal
|
The rate of the band holding |
ccnl_engine.repository.InsuredAbsenceRates
¶
Bases: BaseModel
The statutory indemnities of the bundle.
Attributes:
| Name | Type | Description |
|---|---|---|
maternity |
MaternityRates
|
The INPS maternity indemnity. |
paternity |
PaternityRates
|
The INPS indemnity of the compulsory paternity leave. |
parental |
ParentalRates
|
The INPS indemnity of the parental leave. |
disability_permit |
RestPermitRates
|
The INPS indemnity of the L. 104/1992 permits. |
nursing_rest |
RestPermitRates
|
The INPS indemnity of the daily rests of the first year of a child (artt. 39-41). |
extraordinary_leave |
ExtraordinaryLeaveRates
|
The INPS indemnity of the extraordinary leave. |
injury |
InjuryRates
|
The pay of a temporary inability after a work injury. |
ruleset |
RulesetIdentity | None
|
Identity of the data file. |