Pricing-as-code
One object is the single source of truth for what you charge.
class=kw>from larz.pricing class=kw>import Pricing
class=kw>import larz.money as money
money.enable(app, base_url="https://you.com")
(Pricing()
.plan("free", "$0", limits={"projects": 3})
.plan("pro", "$19/mo", trial_days=14, highlight=True,
features=["API access"], limits={"projects": None, "api": True})
.usage("api_call", "$0.002/call")
.credit_pack("bulk", price="$20", credit="$25")
.coupon("LAUNCH50", percent_off=50)
.mount(app))
This registers the plans, packs, coupons and metered prices with app.money, and
installs a styled /larz/pricing page whose buttons link to
/larz/subscribe/<plan>.
Feature flags & limits
if app.feature(req, "api"): ... class=com># plan grants the "api" feature?
if not app.within_limit(req, "projects", count):
class=kw>return app.money.require(req, "plan:pro") class=com># over the limit -> upsell
plan = app.current_plan(req) class=com># the caller's active plan, or None
limits values: a number caps it, None means unlimited, True
is a boolean capability. Guide: Pricing as code in
Python.