A package to conduct policy analysis using PolicyEngine tax-benefit models.
Project description
PolicyEngine.py
A Python package for tax-benefit microsimulation analysis. Run policy simulations, analyse distributional impacts, and visualise results across the UK and US.
Quick start
from policyengine.core import Simulation
from policyengine.tax_benefit_models.uk import PolicyEngineUKDataset, uk_latest
from policyengine.outputs.aggregate import Aggregate, AggregateType
# Load representative microdata
dataset = PolicyEngineUKDataset(
name="FRS 2023-24",
filepath="./data/frs_2023_24_year_2026.h5",
year=2026,
)
# Run simulation
simulation = Simulation(
dataset=dataset,
tax_benefit_model_version=uk_latest,
)
simulation.run()
# Calculate total universal credit spending
agg = Aggregate(
simulation=simulation,
variable="universal_credit",
aggregate_type=AggregateType.SUM,
entity="benunit",
)
agg.run()
print(f"Total UC spending: £{agg.result / 1e9:.1f}bn")
Documentation
Core concepts:
- Core concepts: Architecture, datasets, simulations, outputs
- UK tax-benefit model: Entities, parameters, examples
- US tax-benefit model: Entities, parameters, examples
Examples:
examples/income_distribution_us.py: Analyse benefit distribution by decileexamples/employment_income_variation_uk.py: Model employment income phase-outsexamples/policy_change_uk.py: Analyse policy reform impacts
Installation
pip install policyengine
Features
- Multi-country support: UK and US tax-benefit systems
- Representative microdata: Load FRS, CPS, or create custom scenarios
- Policy reforms: Parametric reforms with date-bound parameter values
- Distributional analysis: Aggregate statistics by income decile, demographics
- Entity mapping: Automatic mapping between person, household, tax unit levels
- Visualisation: PolicyEngine-branded charts with Plotly
Key concepts
Datasets
Datasets contain microdata at entity level (person, household, tax unit). Load representative data or create custom scenarios:
from policyengine.tax_benefit_models.uk import PolicyEngineUKDataset
dataset = PolicyEngineUKDataset(
name="Representative data",
filepath="./data/frs_2023_24_year_2026.h5",
year=2026,
)
dataset.load()
Simulations
Simulations apply tax-benefit models to datasets:
from policyengine.core import Simulation
from policyengine.tax_benefit_models.uk import uk_latest
simulation = Simulation(
dataset=dataset,
tax_benefit_model_version=uk_latest,
)
simulation.run()
# Access calculated variables
output = simulation.output_dataset.data
print(output.household[["household_net_income", "household_benefits"]])
Outputs
Extract insights with aggregate statistics:
from policyengine.outputs.aggregate import Aggregate, AggregateType
# Mean income in top decile
agg = Aggregate(
simulation=simulation,
variable="household_net_income",
aggregate_type=AggregateType.MEAN,
filter_variable="household_net_income",
quantile=10,
quantile_eq=10,
)
agg.run()
print(f"Top decile mean income: £{agg.result:,.0f}")
Policy reforms
Apply parametric reforms:
from policyengine.core import Policy, Parameter, ParameterValue
import datetime
parameter = Parameter(
name="gov.hmrc.income_tax.allowances.personal_allowance.amount",
tax_benefit_model_version=uk_latest,
data_type=float,
)
policy = Policy(
name="Increase personal allowance",
parameter_values=[
ParameterValue(
parameter=parameter,
start_date=datetime.date(2026, 1, 1),
end_date=datetime.date(2026, 12, 31),
value=15000,
)
],
)
# Run reform simulation
reform_sim = Simulation(
dataset=dataset,
tax_benefit_model_version=uk_latest,
policy=policy,
)
reform_sim.run()
Country models
UK
Three entity levels:
- Person: Individual with income and demographics
- Benunit: Benefit unit (single person or couple with children)
- Household: Residence unit
Key benefits: Universal Credit, Child Benefit, Pension Credit Key taxes: Income tax, National Insurance
US
Six entity levels:
- Person: Individual
- Tax unit: Federal tax filing unit
- SPM unit: Supplemental Poverty Measure unit
- Family: Census family definition
- Marital unit: Married couple or single person
- Household: Residence unit
Key benefits: SNAP, TANF, EITC, CTC, SSI, Social Security Key taxes: Federal income tax, payroll tax
Contributing
See CONTRIBUTING.md for development setup and guidelines.
License
AGPL-3.0
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file policyengine-3.1.2.tar.gz.
File metadata
- Download URL: policyengine-3.1.2.tar.gz
- Upload date:
- Size: 177.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85f01110d9173dfb65c5d3b8d7611b55acd8d115df46ada4b4333e5abcfc18c9
|
|
| MD5 |
a95bb23f5a82a592cdb73f77e8eaabee
|
|
| BLAKE2b-256 |
69109fee56b494f88bd8de4a4d48088b083f4b77e61c4e1789dc7e59bc125807
|
File details
Details for the file policyengine-3.1.2-py3-none-any.whl.
File metadata
- Download URL: policyengine-3.1.2-py3-none-any.whl
- Upload date:
- Size: 62.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0026203fc003d973c3ef91e19ecfb73daba3b89f6ec5b60df3ebfac0932f9275
|
|
| MD5 |
3455a065fba9e5168f0323509b451e40
|
|
| BLAKE2b-256 |
afa1d6712ce2479478862914fb500bc3822b4c6c786f53a54a32bedc6f33e01b
|