Skip to main content

Canonical billing models, lifecycle operations, and analytics for the Tigrbl platform.

Project description

Tigrbl Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - tigrbl-billing


Tigrbl Billing 🧾

Full-spectrum billing models, lifecycle operations, and reporting views designed for the Tigrbl platform.

tigrbl-billing packages the canonical product catalog, subscription, invoicing, and credit subsystems into a single distribution so you can drop billing primitives into any Tigrbl deployment.

Features ✨

  • 🗃️ Unified schema for products, prices, tiers, usage events, invoices, webhooks, and Stripe entities.
  • 🔁 Lifecycle operations for subscriptions, invoicing, seat management, grants, and credit charging backed by lazily imported tigrbl_billing.ops helpers.
  • 📈 Analytics-ready views for ARR, MRR, ARPU, retention cohorts, dunning funnels, revenue attribution, and more.
  • 🔌 Gateway helpers that assemble multiple metered, tiered, and checkout API apps in a single call.
  • ☁️ Stripe synchronization utilities to keep local records aligned with upstream events and connected accounts.
  • 🧱 Extensible credit system covering balance top-offs, usage policies, and ledger management.

Installation 📦

Using uv

uv pip install tigrbl-billing

Using pip

pip install tigrbl-billing

tigrbl-billing supports Python 3.10 through 3.12. Workspace builds can source the sibling tigrbl package from this monorepo using uv workspaces.

Quick Start 🚀

from tigrbl.engine.shortcuts import engine
from tigrbl_billing.api import billing_api

# Build a fully loaded billing app with async support.
app = billing_api.build_billing_app(async_mode=True)

# Or selectively compose feature-specific apps.
from tigrbl_billing import gateway
apps = gateway.build_all_apps(async_mode=True)
product_price_api = apps["product_price"]

The exported ASGI apps expose RESTful and JSON-RPC entrypoints backed by the Tigrbl ORM. Models can be imported individually from tigrbl_billing.tables for customization, while operations in tigrbl_billing.ops provide pre-built lifecycle handlers.

Data Model Highlights 🧱

  • CatalogProduct, Price, PriceTier, and Feature mirror Stripe catalog constructs with local metadata extensions.
  • SubscriptionsSubscription, SubscriptionItem, and SeatAllocation capture plan usage and allocation semantics.
  • Usage TrackingUsageEvent and UsageRollup provide granular event ingestion with rollups for metered billing.
  • Invoicing & PaymentsInvoice, InvoiceLineItem, PaymentIntent, and Refund manage billing state machines.
  • Stripe ConnectConnectedAccount, SplitRule, Transfer, and ApplicationFee simplify partner payouts.
  • CreditsCustomerBalance, BalanceTopOff, CreditGrant, CreditLedger, and CreditUsagePolicy deliver a flexible credit system.

Operations & Integrations ⚙️

  • tigrbl_billing.ops.subscription_ops – start, cancel, pause, resume, and trial management.
  • tigrbl_billing.ops.invoice_ops – finalize, void, and mark invoices uncollectible.
  • tigrbl_billing.ops.usage_ops – periodic rollups to hydrate ARR/MRR reporting.
  • tigrbl_billing.ops.credit_usage_ops – charge credits or auto top-off balances.
  • tigrbl_billing.ops.webhook_ops – ingest Stripe webhook payloads safely.
  • tigrbl_billing.ops.sync_ops – sync catalog, subscription, and payment data from Stripe.

Pair these operations with the gateway factory to expose separated micro-apps for product pricing, tiered plans, seat tracking, or checkout experiences.

API Construction Best Practices 🧩

When composing bespoke billing APIs, import only the operations you need. The tigrbl_billing.ops package now exposes a lazy loader so operations register with their bound models only after an API touches them. This keeps global state clean and avoids double registration.

from tigrbl import TigrblApp
from tigrbl.shortcuts.engine import engine, mem

from tigrbl_billing import ops
from tigrbl_billing.tables.subscription import Subscription

# Touch the exact helpers required by this API.
ops.start_subscription
ops.cancel_subscription


def build_app(async_mode: bool = True) -> TigrblApp:
    app = TigrblApp(engine=engine(mem(async_=async_mode)))
    app.include_models([Subscription])
    return app

Avoid wrapping these helpers with new @op_ctx decorators—doing so would rebind the already decorated operations and can lead to duplicate aliases. Load the helpers, include the relevant models, and the bound operations will be ready to serve.

Analytics Views 📊

The tigrbl_billing.views package includes ready-to-query SQL views such as:

  • arr_customer and arpu_monthly for revenue optics.
  • cohort_retention and dunning_funnel for lifecycle intelligence.
  • revenue_by_split_rule and usage_coverage_ratio for partner and consumption analytics.

Each view is declared using the Tigrbl ORM spec helpers so they can be materialized or queried directly.

Development 🛠️

Clone the Swarmauri SDK monorepo and install dependencies with uv:

uv sync
uv run --directory pkgs/standards/tigrbl_billing --package tigrbl-billing ruff format .
uv run --directory pkgs/standards/tigrbl_billing --package tigrbl-billing ruff check .

We welcome issues and pull requests that expand the schema, operations, or analytics portfolio.

License 📜

Apache-2.0. See the LICENSE file for details.

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

tigrbl_billing-0.1.2.dev11.tar.gz (36.8 kB view details)

Uploaded Source

Built Distribution

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

tigrbl_billing-0.1.2.dev11-py3-none-any.whl (78.0 kB view details)

Uploaded Python 3

File details

Details for the file tigrbl_billing-0.1.2.dev11.tar.gz.

File metadata

  • Download URL: tigrbl_billing-0.1.2.dev11.tar.gz
  • Upload date:
  • Size: 36.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for tigrbl_billing-0.1.2.dev11.tar.gz
Algorithm Hash digest
SHA256 63ffddb6c7884896ee7347a2066b80a9a74a3d16949ebfa3edc88141b90870b0
MD5 94635ab90eedb4d2fcea278dd490e13d
BLAKE2b-256 d431c32d0a2e5f49ea2934c6dea1d322898b7982b25121df2446422c9dbb135b

See more details on using hashes here.

File details

Details for the file tigrbl_billing-0.1.2.dev11-py3-none-any.whl.

File metadata

  • Download URL: tigrbl_billing-0.1.2.dev11-py3-none-any.whl
  • Upload date:
  • Size: 78.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for tigrbl_billing-0.1.2.dev11-py3-none-any.whl
Algorithm Hash digest
SHA256 63f5b2b7a6a88f3d97e3cfa606342a9d278326850ccf9ae0cc5c7e09cda9adab
MD5 74b27ba9bc7af4fe0ea6f5111d09d9f3
BLAKE2b-256 f3b4dc6c09e65cc8641ade3cec5d3bbe085fc847a85385178f533a1f0d739937

See more details on using hashes here.

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