Metadata-Version: 2.4
Name: integrateledger
Version: 0.1.0
Summary: Python client for the Ledger billing and usage API
License-Expression: MIT
Project-URL: Documentation, https://docs.integrateledger.com/python-sdk
Project-URL: Homepage, https://docs.integrateledger.com
Keywords: ledger,billing,usage,credits,sdk
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# integrateledger

The server-side Python SDK for Ledger's billing and usage API. Install it with
`python3 -m pip install integrateledger`, then use
`from integrateledger import ledger`. The capitalized `Ledger` class and
`ledger_sdk` import remain available for existing source users. See the
[Ledger docs](https://docs.integrateledger.com/python-sdk) for examples.

From a repository checkout, run the SDK tests with:

```bash
python3 -m pip install ./packages/sdk-python
python3 -m unittest discover -s packages/sdk-python/tests -v
```

```python
import os
from integrateledger import ledger

client = ledger(api_key=os.environ["LEDGER_API_KEY"])
client.create_feature(id="api_call", name="API call", credit_cost=1)
client.create_plan(id="starter", name="Starter", monthly_credits=100, monthly_price_cents=1900)
client.create_add_on(id="extra_credits", name="Extra credits", credit_amount=50, price_cents=500)
client.create_or_get_customer(customer_id="buyer_123")
customer = client.get_customer(customer_id="buyer_123")
subscriptions = client.list_customer_subscriptions(customer_id="buyer_123")
purchases = client.list_customer_purchases(customer_id="buyer_123")
# Use an active paid subscription ID from the subscriptions list.
client.set_subscription_cancellation(customer_id="buyer_123", subscription_id=42, cancel_at_period_end=True)
```

Methods return response dictionaries and use Python `snake_case` arguments. The client maps them to Ledger's JSON contract and sends the organization key in the `Authorization` header. Pass `base_url="http://127.0.0.1:3001"` for a local API.

Use a `ledger_test_` key for Sandbox or a `ledger_live_` key for Live. The key chooses the environment; the client methods and API URL stay the same. Store these keys in separate server-side variables, and complete sandbox validation before enabling live payments.
