# Vayu API Client Library
## Overview
The Vayu API client library in Python allows you to submit events for processing and storage, manage billing-related entities, and perform various other operations seamlessly.
## Installation
Install the Vayu API client library using pip:
```bash
pip install vayu-client
```
## Usage
### Initialization
Initialize the Vayu API client. The `base_url` parameter is optional and defaults to Vayu's public API servers.
```python
from vayu_api_client import VayuClient
vayu = VayuClient(
access_token='your-access-token',
base_url='https://connect.withvayu.com' # Optional
)
```
### Authentication
#### Login and Obtain Access Token
To obtain a new access token, use the login method:
```python
response = vayu.auth.login({
'refresh_token': 'your-refresh-token'
})
print(response['access_token'])
```
### Events
#### Sending Events
To send a batch of events for processing and storage:
```python
events = [
{
'name': 'api_call', # The distinctive label assigned to an event
'timestamp': '2023-09-13T18:25:43.511Z', # The exact moment of event occurrence in ISO 8601 format
'customer_alias': 'customer_12345', # A unique identifier assigned to each customer
'ref': '4f6cf35x-2c4y-483z-a0a9-158621f77a21', # A universally unique identifier for each event
'data': {
'key1': 'processing_duration', # Example additional data
'key2': 'api_url' # Example additional data
}
}
]
response = vayu.events.send_events({'events': events})
print(response['valid_events'])
print(response['invalid_events'])
```
#### Querying Events
To fetch events occurring within a specified timestamp range:
```python
response = vayu.events.query_events({
'start_time': '2023-09-01T00:00:00.000Z',
'end_time': '2023-09-30T23:59:59.999Z',
'event_name': 'api_call',
'limit': 10
})
print(response['events'])
```
#### Getting Event by Ref ID
To get a specific event using its reference ID:
```python
response = vayu.events.get_event_by_ref_id('4f6cf35x-2c4y-483z-a0a9-158621f77a21')
print(response['event'])
```
#### Deleting Event by Ref ID
To delete a specific event using its reference ID:
```python
response = vayu.events.delete_event_by_ref_id('4f6cf35x-2c4y-483z-a0a9-158621f77a21')
print(response['event'])
```
### Customers
#### Creating a Customer
To create a new customer:
```python
response = vayu.customers.create_customer({
'name': 'John Doe',
'alias': 'customer_12345'
})
print(response['customer'])
```
#### Updating a Customer
To update an existing customer by ID:
```python
response = vayu.customers.update_customer('customer-id', {
'name': 'Jane Doe',
'alias': 'customer_67890'
})
print(response['customer'])
```
#### Deleting a Customer
To delete a customer by ID:
```python
response = vayu.customers.delete_customer('customer-id')
print(response['customer'])
```
### Meters
Meters are entities that track and aggregate usage data based on events. They are crucial for billing and monitoring purposes. Each meter is associated with a specific event name and has an aggregation method to sum up usage values.
#### Getting a Meter by ID
To get a meter by ID:
```python
response = vayu.meters.get_meter('meter-id')
print(response['meter'])
```
#### Updating a Meter
To update a meter by ID:
```python
response = vayu.meters.update_meter('meter-id', {
'name': 'Updated Meter Name',
'event_name': 'api_call',
'aggregation_method': {
'operator': 'Sum',
'field': 'usage',
},
'filter': {
'conditions': [
{
'criterions': [
{
'field': 'event',
'operator': 'Equals',
'value': 'api_call'
}
]
}
]
}
})
print(response['meter'])
```
#### Deleting a Meter
To delete a meter by ID:
```python
response = vayu.meters.delete_meter('meter-id')
print(response['meter'])
```
## Features
The Vayu API client library provides access to the following features:
- **Auth**
- `auth.login()`
- **Events**
- `events.send_events()`
- `events.query_events()`
- `events.get_event_by_ref_id()`
- `events.delete_event_by_ref_id()`
- `events.send_events_dry_run()`
- **Customers**
- `customers.create_customer()`
- `customers.update_customer()`
- `customers.delete_customer()`
- `customers.list_customers()`
- `customers.get_customer()`
- **Meters**
- `meters.get_meter()`
- `meters.update_meter()`
- `meters.delete_meter()`
- `meters.list_meters()`
- **Plans**
- `plans.get_plan()`
- `plans.delete_plan()`
- `plans.list_plans()`
- **Contracts**
- `contracts.create_contract()`
- `contracts.delete_contract()`
- `contracts.list_contracts()`
- `contracts.get_contract()`
- **Invoices**
- `invoices.get_invoice()`
- `invoices.list_invoices()`
## Support
If you have any questions or need further assistance, please contact Vayu at `team@withvayu.com`.
## License
This project is licensed under the MIT License.
---
This README provides an overview and usage examples for the Vayu API client library. For more detailed information on each method, please refer to the official Vayu API documentation.
Raw data
{
"_id": null,
"home_page": "https://withvayu.com",
"name": "vayu-client",
"maintainer": null,
"docs_url": null,
"requires_python": "==3.7.*",
"maintainer_email": null,
"keywords": "vayu, billing, events, python, sdk",
"author": "Vayu, Inc.",
"author_email": "team@withvayu.com",
"download_url": "https://files.pythonhosted.org/packages/78/7a/67bf9afe4a39714209f52107a4aeedf71200b1626e68ff5a78a5b007ebd6/vayu_client-1.0.10.tar.gz",
"platform": null,
"description": "# Vayu API Client Library\n\n## Overview\n\nThe Vayu API client library in Python allows you to submit events for processing and storage, manage billing-related entities, and perform various other operations seamlessly.\n\n## Installation\n\nInstall the Vayu API client library using pip:\n\n```bash\npip install vayu-client\n```\n\n## Usage\n\n### Initialization\n\nInitialize the Vayu API client. The `base_url` parameter is optional and defaults to Vayu's public API servers.\n\n```python\nfrom vayu_api_client import VayuClient\n\nvayu = VayuClient(\n access_token='your-access-token',\n base_url='https://connect.withvayu.com' # Optional\n)\n```\n\n### Authentication\n\n#### Login and Obtain Access Token\n\nTo obtain a new access token, use the login method:\n\n```python\nresponse = vayu.auth.login({\n 'refresh_token': 'your-refresh-token'\n})\n\nprint(response['access_token'])\n```\n\n### Events\n\n#### Sending Events\n\nTo send a batch of events for processing and storage:\n\n```python\nevents = [\n {\n 'name': 'api_call', # The distinctive label assigned to an event\n 'timestamp': '2023-09-13T18:25:43.511Z', # The exact moment of event occurrence in ISO 8601 format\n 'customer_alias': 'customer_12345', # A unique identifier assigned to each customer\n 'ref': '4f6cf35x-2c4y-483z-a0a9-158621f77a21', # A universally unique identifier for each event\n 'data': {\n 'key1': 'processing_duration', # Example additional data\n 'key2': 'api_url' # Example additional data\n }\n }\n]\n\nresponse = vayu.events.send_events({'events': events})\n\nprint(response['valid_events'])\nprint(response['invalid_events'])\n```\n\n#### Querying Events\n\nTo fetch events occurring within a specified timestamp range:\n\n```python\nresponse = vayu.events.query_events({\n 'start_time': '2023-09-01T00:00:00.000Z',\n 'end_time': '2023-09-30T23:59:59.999Z',\n 'event_name': 'api_call',\n 'limit': 10\n})\n\nprint(response['events'])\n```\n\n#### Getting Event by Ref ID\n\nTo get a specific event using its reference ID:\n\n```python\nresponse = vayu.events.get_event_by_ref_id('4f6cf35x-2c4y-483z-a0a9-158621f77a21')\n\nprint(response['event'])\n```\n\n#### Deleting Event by Ref ID\n\nTo delete a specific event using its reference ID:\n\n```python\nresponse = vayu.events.delete_event_by_ref_id('4f6cf35x-2c4y-483z-a0a9-158621f77a21')\n\nprint(response['event'])\n```\n\n### Customers\n\n#### Creating a Customer\n\nTo create a new customer:\n\n```python\nresponse = vayu.customers.create_customer({\n 'name': 'John Doe',\n 'alias': 'customer_12345'\n})\n\nprint(response['customer'])\n```\n\n#### Updating a Customer\n\nTo update an existing customer by ID:\n\n```python\nresponse = vayu.customers.update_customer('customer-id', {\n 'name': 'Jane Doe',\n 'alias': 'customer_67890'\n})\n\nprint(response['customer'])\n```\n\n#### Deleting a Customer\n\nTo delete a customer by ID:\n\n```python\nresponse = vayu.customers.delete_customer('customer-id')\n\nprint(response['customer'])\n```\n\n### Meters\n\nMeters are entities that track and aggregate usage data based on events. They are crucial for billing and monitoring purposes. Each meter is associated with a specific event name and has an aggregation method to sum up usage values.\n\n#### Getting a Meter by ID\n\nTo get a meter by ID:\n\n```python\nresponse = vayu.meters.get_meter('meter-id')\n\nprint(response['meter'])\n```\n\n#### Updating a Meter\n\nTo update a meter by ID:\n\n```python\nresponse = vayu.meters.update_meter('meter-id', {\n 'name': 'Updated Meter Name',\n 'event_name': 'api_call',\n 'aggregation_method': {\n 'operator': 'Sum',\n 'field': 'usage',\n },\n 'filter': {\n 'conditions': [\n {\n 'criterions': [\n {\n 'field': 'event',\n 'operator': 'Equals',\n 'value': 'api_call'\n }\n ]\n }\n ]\n }\n})\n\nprint(response['meter'])\n```\n\n#### Deleting a Meter\n\nTo delete a meter by ID:\n\n```python\nresponse = vayu.meters.delete_meter('meter-id')\n\nprint(response['meter'])\n```\n\n## Features\n\nThe Vayu API client library provides access to the following features:\n\n- **Auth**\n - `auth.login()`\n- **Events**\n - `events.send_events()`\n - `events.query_events()`\n - `events.get_event_by_ref_id()`\n - `events.delete_event_by_ref_id()`\n - `events.send_events_dry_run()`\n- **Customers**\n - `customers.create_customer()`\n - `customers.update_customer()`\n - `customers.delete_customer()`\n - `customers.list_customers()`\n - `customers.get_customer()`\n- **Meters**\n - `meters.get_meter()`\n - `meters.update_meter()`\n - `meters.delete_meter()`\n - `meters.list_meters()`\n- **Plans**\n - `plans.get_plan()`\n - `plans.delete_plan()`\n - `plans.list_plans()`\n- **Contracts**\n - `contracts.create_contract()`\n - `contracts.delete_contract()`\n - `contracts.list_contracts()`\n - `contracts.get_contract()`\n- **Invoices**\n - `invoices.get_invoice()`\n - `invoices.list_invoices()`\n\n## Support\n\nIf you have any questions or need further assistance, please contact Vayu at `team@withvayu.com`.\n\n## License\n\nThis project is licensed under the MIT License.\n\n---\n\nThis README provides an overview and usage examples for the Vayu API client library. For more detailed information on each method, please refer to the official Vayu API documentation.\n",
"bugtrack_url": null,
"license": null,
"summary": "Simple and easy to use python package for utilizing vayu billing system",
"version": "1.0.10",
"project_urls": {
"Homepage": "https://withvayu.com"
},
"split_keywords": [
"vayu",
" billing",
" events",
" python",
" sdk"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9d8826900892bf4cae7b5f4ed98e23d17ac5f95ad4eaf7f1700d4d0718f2e9ef",
"md5": "ec224b6c8c4374328e3903095cad1091",
"sha256": "16e8fc011f4c4e3422204b3bf3ab4f33643fa363bac8ae31c5a49466727d4cad"
},
"downloads": -1,
"filename": "vayu_client-1.0.10-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ec224b6c8c4374328e3903095cad1091",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "==3.7.*",
"size": 149854,
"upload_time": "2024-05-16T13:22:37",
"upload_time_iso_8601": "2024-05-16T13:22:37.408290Z",
"url": "https://files.pythonhosted.org/packages/9d/88/26900892bf4cae7b5f4ed98e23d17ac5f95ad4eaf7f1700d4d0718f2e9ef/vayu_client-1.0.10-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "787a67bf9afe4a39714209f52107a4aeedf71200b1626e68ff5a78a5b007ebd6",
"md5": "3c35dd1712935fb5bd96ca68e1332628",
"sha256": "7bf7101524b460f2d6982c0f785b9fd1f6e89ea43a5b4cccc96b95c5e6192822"
},
"downloads": -1,
"filename": "vayu_client-1.0.10.tar.gz",
"has_sig": false,
"md5_digest": "3c35dd1712935fb5bd96ca68e1332628",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "==3.7.*",
"size": 49200,
"upload_time": "2024-05-16T13:22:40",
"upload_time_iso_8601": "2024-05-16T13:22:40.051712Z",
"url": "https://files.pythonhosted.org/packages/78/7a/67bf9afe4a39714209f52107a4aeedf71200b1626e68ff5a78a5b007ebd6/vayu_client-1.0.10.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-16 13:22:40",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "vayu-client"
}