The official Python client for Plutto API
Project description
Plutto Python Client
This library will help you easily integrate Plutto API to your software, making your developer life a little bit more enjoyable.
Installation
Install using pip
$ pip3 install plutto
Note: This SDK requires Python 3.7+
Usage
With this SDK we want to provide a wrapper to the Plutto API with a very intuitive way of use. All the methods were implemented as in the API documentation, we strongly recommend to read it before using this SDK
Quickstart
First of all, you will need a [Plutto] account. After creating it, you can get your API key, which will let you to use the Plutto object. Then, you're ready to use this awesome SDK!
from plutto import Plutto
client = Plutto("your_api_key")
Managers
To manage the resources retrieved by the SDK we use managers. They are python objects that let you with any object inside Plutto API.. All the existing managers are inside the Plutto object. These are:
customersinvoicesmeter_eventspermission_groupsproductssubscriptions
all
Note: this method is only available in customers, invoices, permission_groups and products managers
customers = client.customers.all()
This method returns a a generator with all the instances of the customers resource. But, what if the API can recive more params? kwargs to the rescue! This way you can pass params like q[status_eq] and q[customer_eq] to filter the Invoices. If you want to get invoices with an specific status and customer, you need to pass those params to the request
params = {
"q[status_eq]": "paid",
"q[customer_eq]": "customer_id"
}
invoices = client.invoices.all(**params)
Also, if you pass the lazy=False parameter, this will force the method of the SDK to return a list of the instances of the resource, instead of the generetors of them. Disclaimer: This could take very long if you have a lot of instances to be retrieved.
customers = client.customers.all(lazy=False)
isinstance(customers, list) # True
get
Note: this method is only available in customers and invoices managers
This method returns an instance of a resource using it's identifier to find it
customer = client.customers.get("customer_id")
isinstance(customer, Customer) # True
create
Note: this method is only available in customers, meter_events and subscriptions managers
This method creates and returns a new instance of the resource. The attributes of the resource to be created must be passed as kwargs. This parameters are specified in the API documentation of the correspondant resource
payload = {
"identifier": "your-id_12885305",
"email": "donald@getplutto.com",
"name": "Donald",
"billing_information": {
"city": "Santiago",
"country_iso_code": "CL",
"state": "Metropolitana",
"address": "Av. Las Condes",
"zip": "12345",
"tax_id": "73245432-1",
"legal_name": "Plutto Inc",
"activity": "Software Development",
"phone": "+56912345678"
}
}
customer = client.customer.create(**payload)
update
Note: this method is only available in customers manager
customer = client.cuestomers.update(
"user_id",
email="goofy@getplutto.com",
name="Goofy"
)
This is an example of how can be used the update method. The first parameter corresponds to the id of the customer, this way the manager can find the existing resource. Then, the attributes that want to be modified are passed as kwargs, this ones are specified in the API in the correspondant resource update method.
This manager method is making two calls to the Plutto API, the first, to get the resource, and the second to update it. Therefore, if you only want to make one API call and already got the reource python object, you can call update directly on the object
# Get the object
example_customer = client.customers.get("customer_id")
# Update the customer
example_customer.update(
email="goofy@getplutto.com",
name="Goofy"
)
This way, you can call update on the objects you are already working with, evitating to make an innescesary API call and saving some words
delete
Note: this method is only available in customers manager
deleted_customer_id = client.customers.delete("customer_id")
This method deletes an existing instance of a resource by it's identifier, and returns it. As in the update method, you can call delete on an resource object, for the same reasons explained in the previous method
# Get the resource
customer = client.customers.get("customer_id")
# Delete de resource
deleted_customer_id = customer.delete()
How to use this SDK
The way to use is very similar to the API. For all the methods you need the Plutto object
Plutto object
Instantiate the object using your secret API key
from plutto import Plutto
client = Plutto("secret_api_key")
This client will give you access to all the managers that are available in this SDK. That means you can work with any manager you want from this object
customers manager
Available methods: all, get, create, update and delete
From the Plutto object you can manage your customers easily. You can get all the customers that have been created
customers = client.customers.all()
for customer in customers:
print(customer.name)
Also, if you have the id, you can get a singular customer
customer = client.customers.get("id_of_the_customer")
Need a new customer? Creating it is very intuitive, just pass the parameters specified in the docs as kwargs
payload = {
"email": "donald@getplutto.com",
"name": "donald",
"billing_information": {
"city": "Santiago",
"country_iso_code": "CL",
"legal_name": "Plutto",
"activity": "Software Development"
}
}
new_customer = client.customers.create(**payload)
If any customers need to be updated, you can do it with it's id and pass the params you want to update as kwargs
update_params = {
"name": "Goofy",
"email": "goofy@getplutto.com"
}
updated_customer = client.customers.update("update_customer_id", **update_params)
# It can also be done this way
update_params = {
"name": "Goofy",
"email": "goofy@getplutto.com"
}
customer = client.customers.get("update_customer_id")
updated_customer = customer.update(**update_params)
Delete a customer can be done by passing it's id to the delete method
deleted_customer_id = client.customers.delete("delete_customer_id")
# It can also be done this way
customer = client.customers.get("delete_customer_id")
deleted_customer_id = customer.delete()
subscriptions manager
To create a new subscription through the manager you can do the following. The attributes must be passed as kwargs. Required and optional ones are specified in the docs
payload = {
"customer_id": "example_customer_id",
"pricing_ids": ["example_pricing_id_1", "example_pricing_id_2"]
"bills_at": "start",
"billing_period_duration": "P0Y1M0DT0H0M0S"
}
subscription = client.subscriptions.create(**payload)
To end a subscription you only need the id
subscription = client.subscriptions.end("subscription_id")
Adding a product pricing to a subscription
# pricing_ids can have only one item, but it must be a list
payload = {
"pricing_ids": ["pricing_id_1", "pricing_id_2", "pricing_id_3"]
}
subscription = client.subscriptions.add_pricings("subscription_id", **payload)
To remove a pricing, you can do the following
# pricing_ids can have only one item, but it must be a list
payload = {
"pricings_id": ["pricing_id_1", "pricing_id_2", "pricing_id_3"]
}
subscription = client.subscriptions.remove_pricings("subscription_id", **payload)
Serialization
Any resource retrieved by the SDK can be serialize, and it's super easy to do it. You just need to call the serialize method, and it's available in any resource
customer = client.customers.get("customer_id")
serialized_customer = customer.serialize()
serialized_customer corresponds to a dictionary with only the attributes of the retrieved resource. It can be JSON-serialized
Testing
All the tests must be added in the tests/ directory. To run the tests you nedd to execute the following command on the root path of the plutto library
pytest .
Every piece of code modified or added must be tested. The coverage always have to be increased or maintained, this will be checked in all PR
Publishing
On master/main branch...
- Change
VERSIONinplutto//version.py. - Change
Unreleasedtitle to current version inCHANGELOG.md. - Commit new release. For example:
Releasing v0.1.0. - Create tag. For example:
git tag v0.1.0. - Push tag. For example:
git push origin v0.1.0.
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
Credits
Thank you contributors!
Plutto Ruby SDK is maintained by Plutto.
Acknowledgments
This SDK was strongly based on the Fintoc python's SDK, designed by Daniel Leal
License
Plutto Python SDK is © 2021 plutto, spa. It is free software and may be redistributed under the terms specified in the LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file plutto-0.1.0.tar.gz.
File metadata
- Download URL: plutto-0.1.0.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.7.4 Darwin/20.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
173c2d844c685b6e35371410201a4d1e9a4d332973ee64bbbefd374746b92c1e
|
|
| MD5 |
45f0af03c5f1728d213d49016fabf698
|
|
| BLAKE2b-256 |
e9ddf78d87fdbe55d028c17423b0d7c3cb681fd2e71915c2f5888c35473b7360
|
File details
Details for the file plutto-0.1.0-py3-none-any.whl.
File metadata
- Download URL: plutto-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.11 CPython/3.7.4 Darwin/20.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e72710cfd696cbee4b496b3ca568408cb65c861e18a5c4aa2c17124d0f631e2
|
|
| MD5 |
d72d450cb14a8fc11eacbceb7c7b7f2d
|
|
| BLAKE2b-256 |
d1510e290d086214d8247ec3a58193f3dc356f3840db8f9dfbce3153d3fc9699
|