mathspp
  • Blog
    • Pydon'ts
    • Problems
    • TIL
    • Twitter threads
  • Books
  • Talks
  • Trainings
    • Advanced iteration
    • Python for scripting and automation
    • Rust for Python developers
  • Courses
  • About
Link blog

tariff · PyPI

on 15-04-2025 15:47 (via)

The parody Python package tariff can be used to impose import tariffs on other modules! The example from the package README:

import tariff

# Set your tariff rates (package_name: percentage)
tariff.set({
    "numpy": 50,     # 50% tariff on numpy
    "pandas": 200,   # 200% tariff on pandas
    "requests": 150  # 150% tariff on requests
})

# Now when you import these packages, they'll be TARIFFED!
import numpy   # This will be 50% slower
import pandas  # This will be 200% slower

I don't know exactly how this is done, but I would guess it's enough to:

  • use tariff.set to set some sort of hook or “watcher” on the import system; and then
  • when doing the actual import, time it and then just sleep for the time set by the import tariff.

Previous link Next link

WolframAlpha helped me a lot when studying for Calculus...

mathspp
  • Blog
    • Pydon'ts
    • Problems
    • TIL
    • Twitter threads
  • Books
  • Talks
  • Trainings
    • Advanced iteration
    • Python for scripting and automation
    • Rust for Python developers
  • Courses
  • About