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, mem
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.engine.shortcuts import engine as build_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=build_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.dev7.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.dev7-py3-none-any.whl (78.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tigrbl_billing-0.1.2.dev7.tar.gz
  • Upload date:
  • Size: 36.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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.dev7.tar.gz
Algorithm Hash digest
SHA256 9c1afc1b4b602138bbbdd91a55e412b8cd83b181c109226806599e4513a85fc6
MD5 00a471e53d2d4d1f9f2f2a787fa63b57
BLAKE2b-256 f2b1837254c2ebbcdf7c825aabca32f5e79264e8fe12aafe71eda7b3de19148d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tigrbl_billing-0.1.2.dev7-py3-none-any.whl
  • Upload date:
  • Size: 78.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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.dev7-py3-none-any.whl
Algorithm Hash digest
SHA256 74e71a530bf1a3264fa725fb0fd59d3f2fec6ee990926dce1bbcc076393640b2
MD5 701b563c8971441ca4ffcc6a851bad81
BLAKE2b-256 38f4bd85108de0ec66e45fd30e8194832aae8f480e8c2fdf07907ae3791d08f8

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