Skip to main content

Principles of Economics toolkit for demand/supply analytics and diagrams.

Project description

principle-econ

CI / Publish PyPI Python

principle-econ is a Python package for Principles of Economics market analysis and diagrams. It focuses on linear demand/supply models with clean module boundaries across solver logic, policy layers, welfare decomposition, and plotting.

Features

  • Solve market equilibrium from two linear equations
  • Comparative statics with direction metadata
  • Tax analysis: fixed, per-unit, ad valorem, and legal incidence side
  • Price controls: ceiling/floor with shortage/surplus
  • Welfare decomposition: CS, PS, tax revenue, TS, DWL
  • Renderer-friendly polygon outputs and labeled welfare regions
  • CLI workflows with JSON output
  • Example figures generated in monochrome style for teaching slides

Installation

pip install principle-econ

For development:

git clone https://github.com/EconViz/principle-econ.git
cd principle-econ
poetry install --with dev

Quick Start

from principle_econ.core.line import Line
from principle_econ.core.equilibrium import solve_equilibrium
from principle_econ.plot.figure import MarketFigure

demand = Line.from_inverse(10.0, -1.0)
supply = Line.from_inverse(2.0, 1.0)
eq = solve_equilibrium(demand, supply)

fig = MarketFigure(x_max=12, y_max=12, title="Basic Equilibrium", palette="monochrome")
fig.add_curves(demand, supply, q_max=10)
fig.add_equilibrium(eq)
fig.finalize()
fig.save("basic_equilibrium.png")
fig.close()

Tax Example (Consumer vs Producer Incidence)

from principle_econ.core.line import Line
from principle_econ.plot.figure import MarketFigure
from principle_econ.policy.tax import TaxOn, TaxScenario, TaxType

demand = Line.from_inverse(10.0, -1.0)
supply = Line.from_inverse(0.0, 1.0)
scenario = TaxScenario(tax_type=TaxType.AD_VALOREM_TAX, amount=0.2, tax_on=TaxOn.CONSUMER)

fig = MarketFigure(x_max=11, y_max=11, title="Ad Valorem Tax", palette="monochrome")
fig.add_curves(demand, supply, q_max=10)
fig.add_tax_transform(demand, supply, scenario, q_max=10)
fig.finalize(legend=True)
fig.save("tax_ad_valorem_consumer.png")
fig.close()

CLI

principle-econ equilibrium \
  --demand-intercept 10 --demand-slope -1 \
  --supply-intercept 2 --supply-slope 1

principle-econ tax \
  --demand-intercept 10 --demand-slope -1 \
  --supply-intercept 2 --supply-slope 1 \
  --tax-type per_unit --amount 1 --tax-on producer

Examples

Run all examples:

poetry run python examples/scipts/run_all.py

Generated images are grouped by topic under examples/output/:

  • equilibrium/
  • taxation/
  • price_controls/
  • welfare/
  • elasticity/

Development

poetry run ruff check src tests examples/scipts
poetry run pytest -q
poetry build

PyPI Publishing

This repository is configured to publish from GitHub Actions using Trusted Publishing.

  • Workflow: .github/workflows/publish.yml
  • Trigger: push tag v* (for example v0.1.0)
  • Publisher: pypa/gh-action-pypi-publish@release/v1 with id-token: write

Release helper script (modeled after econ-viz):

scripts/release.sh prepare 0.1.0
scripts/release.sh finalize 0.1.0

Documentation

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

principle_econ-0.1.0.tar.gz (22.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

principle_econ-0.1.0-py3-none-any.whl (35.3 kB view details)

Uploaded Python 3

File details

Details for the file principle_econ-0.1.0.tar.gz.

File metadata

  • Download URL: principle_econ-0.1.0.tar.gz
  • Upload date:
  • Size: 22.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for principle_econ-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1557e202b015691d4a51f8dc4d578c63d0eec7f361908bf3bef9f3acf1d5ddc4
MD5 660d40e44583c66c1c22ed070fd3d8d7
BLAKE2b-256 4047a9143798779607c2bceb7406c6777c3d80e6faa6d3557131b7466194e664

See more details on using hashes here.

Provenance

The following attestation bundles were made for principle_econ-0.1.0.tar.gz:

Publisher: publish.yml on EconViz/principle-econ

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file principle_econ-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: principle_econ-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 35.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for principle_econ-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 effb07ee6ae75ad5dccb33cf53b0df0ae832d197c3d71d7560e70dbf11868575
MD5 4377780ff993917e3e5252997aeb0548
BLAKE2b-256 f72b605f461099f57da828051d7d3e4557c5a3d5b3a2682416c5c3645698ee8a

See more details on using hashes here.

Provenance

The following attestation bundles were made for principle_econ-0.1.0-py3-none-any.whl:

Publisher: publish.yml on EconViz/principle-econ

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page