Skip to main content

Lago Python API Client

Project description

Lago Python Client

This is a python wrapper for Lago API

PyPI version

Installation

Install the lago-python-client via pip from PyPI:

$ pip install lago-python-client

Usage

from lago_python_client import Client

client = Client(api_key = 'key')

Events

Api reference

from lago_python_client.models import Event

event = Event(
    customer_id="5eb02857-a71e-4ea2-bcf9-57d8885990ba",
    transaction_id="__UNIQUE_ID__",
    code="123",
    timestamp=1650893379,
    properties={"custom_field": "custom"}
)

client.events().create(event)
transaction_id = "6afadc2a-f28c-40a4-a868-35636f229765"
event = client.events().find(transaction_id)

Customers

Api reference

from lago_python_client.models import Customer, BillingConfiguration

customer = Customer(
    customer_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('customer_id')

Invoices

Api reference

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})

Organizations

Api reference

from lago_python_client.models import Organization

params = Organization(
    webhook_url="https://new.url",
    vat_rate=14.2
)
client.organizations().update(params)

Invoice Download

invoice = client.invoices().download('5eb02857-a71e-4ea2-bcf9-57d8885990ba')

Subscriptions

Api reference

from lago_python_client.models import Subscription

subscription = Subscription(
    customer_id="5eb02857-a71e-4ea2-bcf9-57d8885990ba",
    plan_code="code"
)
client.subscriptions().create(subscription)

params_delete = {
    "customer_id": "5eb02857-a71e-4ea2-bcf9-57d8885990ba"
}
client.subscriptions().delete(params_delete)

Applied coupons

Api reference

from lago_python_client.models import AppliedCoupon

applied_coupon = AppliedCoupon(
  customer_id="5eb02857-a71e-4ea2-bcf9-57d3a41bc6ba",
  coupon_code="code",
  amount_cents=123,
  amount_currency="EUR"
)

client.applied_coupons().create(applied_coupon)

Applied add-ons

Api reference

from lago_python_client.models import AppliedAddOn

applied_add_on = AppliedAddOn(
  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)

Billable metrics

Api reference

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})

Coupons

Api reference

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})

Add-ons

Api reference

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})

Plans

Api reference

from lago_python_client.models import Plan, Charges, Charge

charge = Charge(
    billable_metric_id='id',
    charge_model='standard',
    amount_currency='EUR',
    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})

Development

Install the dependencies

pip install .

Run tests

python3 -m unittest tests

Documentation

The Lago documentation is available at doc.getlago.com.

Contributing

The contribution documentation is available here

License

Lago Python client is distributed under AGPL-3.0.

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

lago-python-client-0.3.0.tar.gz (25.5 kB view details)

Uploaded Source

Built Distribution

lago_python_client-0.3.0-py3-none-any.whl (40.3 kB view details)

Uploaded Python 3

File details

Details for the file lago-python-client-0.3.0.tar.gz.

File metadata

  • Download URL: lago-python-client-0.3.0.tar.gz
  • Upload date:
  • Size: 25.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for lago-python-client-0.3.0.tar.gz
Algorithm Hash digest
SHA256 7f8328a09bbb5da86674d9672ca4ffe40c31b3631d3aab426355f91725a54535
MD5 df1374ca766bba4e9c9d080dc1852a08
BLAKE2b-256 af70c5cd781c88d24409cce6c4514f2d40fd08a4d699197353f2aed6807d7a5d

See more details on using hashes here.

File details

Details for the file lago_python_client-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for lago_python_client-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c3a142432d1e1821d56c00c83d173ba4ad996a79910d1fd1eb5c7411b9c101b0
MD5 ffcec3fab3bd500b288cb08e4468c657
BLAKE2b-256 a48f1329dbbbfd0b4c5dde8b68d9968f5d504ede6305c9f0d335fd4cb07e6d29

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page