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.dev13.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.dev13-py3-none-any.whl (78.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tigrbl_billing-0.1.2.dev13.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.dev13.tar.gz
Algorithm Hash digest
SHA256 c8dfc0bfebe9e9db6e8e69db22fc72c914a553eebbc5c8eda92f4b02e21dd97a
MD5 5c0b9b1b29592804d28be1ae285190f9
BLAKE2b-256 88416f32e05f4e6330ad4d534e48740f0887fb1aefa0c2c05d192677f8f7d2d5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tigrbl_billing-0.1.2.dev13-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.dev13-py3-none-any.whl
Algorithm Hash digest
SHA256 3aa738ef5e9b1ae9c8378ea26c9253d90ce23ff4775fe5b0f8db0c9a75d4bcd0
MD5 25f84df12caf24b7cb483a9c574dbf02
BLAKE2b-256 0534599bc23654f3d731c89396fa1100ab6d4b6282ce5f12d582b20983873164

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