Lago Python API 客户端
项目描述
Lago Python 客户端
这是 Lago API 的 python 包装器
安装
从 PyPI 通过 pip 安装 lago-python-client:
$ pip install lago-python-client
用法
from lago_python_client import Client
client = Client(api_key = 'key')
活动
from lago_python_client.models import Event, BatchEvent
event = Event(
external_customer_id="5eb02857-a71e-4ea2-bcf9-57d8885990ba",
transaction_id="__UNIQUE_ID__",
code="123",
timestamp=1650893379,
properties={"custom_field": "custom"}
)
client.events().create(event)
event = BatchEvent(
external_subscription_ids=[
"5eb02857-a71e-4ea2-bcf9-57d8885990ba", "8ztrg2857-a71e-4ea2-bcf9-57d8885990ba"],
transaction_id="__UNIQUE_ID__",
code="123",
timestamp=1650893379,
properties={"custom_field": "custom"}
)
client.events().batch_create(event)
transaction_id = "6afadc2a-f28c-40a4-a868-35636f229765"
event = client.events().find(transaction_id)
顾客
from lago_python_client.models import Customer, BillingConfiguration
customer = Customer(
external_id="5eb02857-a71e-4ea2-bcf9-57d8885990ba",
address_line1=None,
address_line2=None,
city=None,
country=None,
email="test@example.com",
legal_name=None,
legal_number=None,
logo_url=None,
name="test name",
phone=None,
state=None,
url=None,
vat_rate=None,
zipcode=None,
billing_configuration=BillingConfiguration(
payment_provider=None,
provider_customer_id=None,
sync=None
)
)
client.customers().create(customer)
customer_usage = client.customers().current_usage('external_customer_id', 'subscription_id')
发票
from lago_python_client.models import InvoiceStatusChange
status_change = InvoiceStatusChange(
status="succeeded"
)
client.invoices().update(status_change, '5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba')
client.invoices().find('5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba')
client.invoices().find_all({'per_page': 2, 'page': 1})
组织
from lago_python_client.models import Organization
params = Organization(
webhook_url="https://new.url",
vat_rate=14.2
)
client.organizations().update(params)
发票下载
invoice = client.invoices().download('5eb02857-a71e-4ea2-bcf9-57d8885990ba')
订阅
from lago_python_client.models import Subscription
subscription = Subscription(
external_customer_id="5eb02857-a71e-4ea2-bcf9-57d8885990ba",
plan_code="code",
external_id="12345",
name="display name"
billing_time="anniversary"
)
client.subscriptions().create(subscription)
update_params = Subscription(
name='new name'
)
client.subscriptions().update(update_params, 'id')
client.subscriptions().destroy('id')
client.subscriptions().find_all({'external_customer_id': '123'})
应用优惠券
from lago_python_client.models import AppliedCoupon
applied_coupon = AppliedCoupon(
external_customer_id="5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba",
coupon_code="code",
amount_cents=123,
amount_currency="EUR"
)
client.applied_coupons().create(applied_coupon)
应用的附加组件
from lago_python_client.models import AppliedAddOn
applied_add_on = AppliedAddOn(
external_customer_id="5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba",
add_on_code="code",
amount_cents=123,
amount_currency="EUR"
)
client.applied_add_ons().create(applied_add_on)
可计费指标
from lago_python_client.models import BillableMetric
billable_metric = BillableMetric(
name='name',
code='code_first',
description='desc',
aggregation_type='sum_agg',
field_name='amount_sum'
)
client.billable_metrics().create(billable_metric)
update_params = BillableMetric(
name='new name'
)
client.billable_metrics().update(update_params, 'code')
client.billable_metrics().find('code')
client.billable_metrics().destroy('code')
client.billable_metrics().find_all({'per_page': 2, 'page': 1})
优惠券
from lago_python_client.models import Coupon
coupon = Coupon(
name='name',
code='code_first',
amount_cents=1000,
amount_currency='EUR',
expiration='no_expiration',
expiration_duration=10
)
client.coupons().create(coupon)
update_params = Coupon(
name='new name'
)
client.coupons().update(update_params, 'code')
client.coupons().find('code')
client.coupons().destroy('code')
client.coupons().find_all({'per_page': 2, 'page': 1})
附加组件
from lago_python_client.models import AddOn
add_on = AddOn(
name='name',
code='code_first',
amount_cents=1000,
amount_currency='EUR',
description='desc'
)
client.add_ons().create(add_on)
update_params = AddOn(
name='new name'
)
client.add_ons().update(update_params, 'code')
client.add_ons().find('code')
client.add_ons().destroy('code')
client.add_ons().find_all({'per_page': 2, 'page': 1})
计划
from lago_python_client.models import Plan, Charges, Charge
charge = Charge(
billable_metric_id='id',
charge_model='standard',
properties={
'amount': '0.22'
}
)
charges = Charges(__root__=[charge])
plan = Plan(
name='name',
code='code_first',
amount_cents=1000,
amount_currency='EUR',
description='desc',
interval='weekly',
pay_in_advance=True,
charges=charges
)
client.plans().create(plan)
update_params = Plan(
name='new name'
)
client.plans().update(update_params, 'code')
client.plans().find('code')
client.plans().destroy('code')
client.plans().find_all({'per_page': 2, 'page': 1})
钱包
from lago_python_client.models import Wallet
wallet = Wallet(
external_customer_id='123',
name='name1',
rate_amount='1',
paid_credits='10',
granted_credits='10'
)
client.wallets().create(wallet)
update_params = Wallet(
name='new name'
)
client.wallets().update(update_params, 'id')
client.wallets().find('id')
client.wallets().destroy('id')
client.wallets().find_all({'external_customer_id': 123, 'per_page': 2, 'page': 1})
钱包交易
from lago_python_client.models import WalletTransaction
wallet_transaction = WalletTransaction(
wallet_id='123',
paid_credits='10',
granted_credits='10'
)
client.wallet_transactions().create(wallet_transaction)
发展
安装依赖项
pip install .
运行测试
python3 -m unittest tests
文档
Lago 文档可在doc.getlago.com上找到。
贡献
贡献文档可在此处获得
执照
Lago Python 客户端在AGPL-3.0下分发。
项目详情
关
lago_python_client -0.6.0-py3-none-any.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | c4d3188f0dba426de1607b5a6d068dcd6cb0f3a07d3969e661f89b7aa59067d7 |
|
| MD5 | ee034b4d5026b139ca41885e9a698fb1 |
|
| 布莱克2-256 | 0c812b418d997423d93dbfb40edaeecefeb4dcffa2a02cea2fb6fa7622a49f73 |