Skip to content

Commit 1749336

Browse files
authored
Merge pull request #20 from databox/python-example
Add Pyhton example
2 parents 8e2e25a + 06e64de commit 1749336

File tree

8 files changed

+72
-679
lines changed

8 files changed

+72
-679
lines changed

README.md

Lines changed: 21 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -45,81 +45,36 @@ import databox
4545

4646
Execute `pytest` to run the tests.
4747

48-
## Getting Started
48+
## Basic example
4949

5050
Please follow the [installation procedure](#installation--usage) and then run the following:
5151

5252
```python
5353

54-
import databox
55-
from databox.rest import ApiException
56-
from pprint import pprint
57-
58-
# Defining the host is optional and defaults to https://push.databox.com
59-
# See configuration.py for a list of all supported configuration parameters.
60-
configuration = databox.Configuration(
61-
host = "https://push.databox.com"
62-
)
63-
64-
# The client must configure the authentication and authorization parameters
65-
# in accordance with the API server security policy.
66-
# Examples for each auth method are provided below, use the example that
67-
# satisfies your auth use case.
68-
69-
# Configure HTTP basic authorization: basicAuth
54+
# Configuration setup for the Databox API client
55+
# The API token is used as the username for authentication
56+
# It's recommended to store your API token securely, e.g., in an environment variable
7057
configuration = databox.Configuration(
71-
username = os.environ["USERNAME"],
72-
password = os.environ["PASSWORD"]
73-
)
58+
host = "https://push.databox.com",
59+
username = "<YOUR-CUSTOM-DATA-TOKEN>",
60+
password = ""
61+
)
7462

63+
# It's crucial to specify the correct Accept header for the API request
64+
with databox.ApiClient(configuration, "Accept", "application/vnd.databox.v2+json",) as api_client:
65+
api_instance = databox.DefaultApi(api_client)
7566

76-
# Enter a context with an instance of the API client
77-
with databox.ApiClient(configuration) as api_client:
78-
# Create an instance of the API class
79-
api_instance = databox.DefaultApi(api_client)
67+
# Define the data to be pushed to the Databox Push API# Prepare the data you want to push to Databox
68+
# The 'key' should match a metric in your Databox account, 'value' is the data point, 'unit' is optional, and 'date' is the timestamp of the data point
69+
push_data = [{"key": "sales2", "value": 100, "unit": "USD", "date": "2021-01-01T00:00:00Z" }]
8070

8171
try:
82-
api_instance.data_delete()
72+
api_instance.data_post(push_data=push_data)
8373
except ApiException as e:
84-
print("Exception when calling DefaultApi->data_delete: %s\n" % e)
85-
74+
# Handle exceptions that occur during the API call, such as invalid data or authentication issues
75+
pprint("API Exception occurred: %s\n" % e)
76+
except Exception as e:
77+
# Handle any other unexpected exceptions
78+
pprint("An unexpected error occurred: %s\n" % e)
79+
8680
```
87-
88-
## Documentation for API Endpoints
89-
90-
All URIs are relative to *https://push.databox.com*
91-
92-
Class | Method | HTTP request | Description
93-
------------ | ------------- | ------------- | -------------
94-
*DefaultApi* | [**data_delete**](docs/DefaultApi.md#data_delete) | **DELETE** /data |
95-
*DefaultApi* | [**data_metric_key_delete**](docs/DefaultApi.md#data_metric_key_delete) | **DELETE** /data/{metricKey} |
96-
*DefaultApi* | [**data_post**](docs/DefaultApi.md#data_post) | **POST** /data |
97-
*DefaultApi* | [**metrickeys_get**](docs/DefaultApi.md#metrickeys_get) | **GET** /metrickeys |
98-
*DefaultApi* | [**metrickeys_post**](docs/DefaultApi.md#metrickeys_post) | **POST** /metrickeys |
99-
*DefaultApi* | [**ping_get**](docs/DefaultApi.md#ping_get) | **GET** /ping |
100-
101-
102-
## Documentation For Models
103-
104-
- [ApiResponse](docs/ApiResponse.md)
105-
- [PushData](docs/PushData.md)
106-
- [PushDataAttribute](docs/PushDataAttribute.md)
107-
- [State](docs/State.md)
108-
109-
110-
<a id="documentation-for-authorization"></a>
111-
## Documentation For Authorization
112-
113-
114-
Authentication schemes defined for the API:
115-
<a id="basicAuth"></a>
116-
### basicAuth
117-
118-
- **Type**: HTTP basic authentication
119-
120-
121-
## Author
122-
123-
124-
125-

examples/push_data.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import databox
2+
from databox.rest import ApiException
3+
from pprint import pprint
4+
5+
# Configuration setup for the Databox API client
6+
# The API token is used as the username for authentication
7+
# It's recommended to store your API token securely, e.g., in an environment variable
8+
configuration = databox.Configuration(
9+
host = "https://push.databox.com",
10+
username = "<YOUR-CUSTOM-DATA-TOKEN>",
11+
password = ""
12+
)
13+
14+
# It's crucial to specify the correct Accept header for the API request
15+
with databox.ApiClient(configuration, "Accept", "application/vnd.databox.v2+json",) as api_client:
16+
api_instance = databox.DefaultApi(api_client)
17+
18+
# Define the data to be pushed to the Databox Push API# Prepare the data you want to push to Databox
19+
# The 'key' should match a metric in your Databox account, 'value' is the data point, 'unit' is optional, and 'date' is the timestamp of the data point
20+
push_data = [{"key": "sales2", "value": 100, "unit": "USD", "date": "2021-01-01T00:00:00Z" }]
21+
22+
try:
23+
api_instance.data_post(push_data=push_data)
24+
except ApiException as e:
25+
# Handle exceptions that occur during the API call, such as invalid data or authentication issues
26+
pprint("API Exception occurred: %s\n" % e)
27+
except Exception as e:
28+
# Handle any other unexpected exceptions
29+
pprint("An unexpected error occurred: %s\n" % e)
30+

src/README.md

Lines changed: 21 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -45,81 +45,36 @@ import databox
4545

4646
Execute `pytest` to run the tests.
4747

48-
## Getting Started
48+
## Basic example
4949

5050
Please follow the [installation procedure](#installation--usage) and then run the following:
5151

5252
```python
5353

54-
import databox
55-
from databox.rest import ApiException
56-
from pprint import pprint
57-
58-
# Defining the host is optional and defaults to https://push.databox.com
59-
# See configuration.py for a list of all supported configuration parameters.
60-
configuration = databox.Configuration(
61-
host = "https://push.databox.com"
62-
)
63-
64-
# The client must configure the authentication and authorization parameters
65-
# in accordance with the API server security policy.
66-
# Examples for each auth method are provided below, use the example that
67-
# satisfies your auth use case.
68-
69-
# Configure HTTP basic authorization: basicAuth
54+
# Configuration setup for the Databox API client
55+
# The API token is used as the username for authentication
56+
# It's recommended to store your API token securely, e.g., in an environment variable
7057
configuration = databox.Configuration(
71-
username = os.environ["USERNAME"],
72-
password = os.environ["PASSWORD"]
73-
)
58+
host = "https://push.databox.com",
59+
username = "<YOUR-CUSTOM-DATA-TOKEN>",
60+
password = ""
61+
)
7462

63+
# It's crucial to specify the correct Accept header for the API request
64+
with databox.ApiClient(configuration, "Accept", "application/vnd.databox.v2+json",) as api_client:
65+
api_instance = databox.DefaultApi(api_client)
7566

76-
# Enter a context with an instance of the API client
77-
with databox.ApiClient(configuration) as api_client:
78-
# Create an instance of the API class
79-
api_instance = databox.DefaultApi(api_client)
67+
# Define the data to be pushed to the Databox Push API# Prepare the data you want to push to Databox
68+
# The 'key' should match a metric in your Databox account, 'value' is the data point, 'unit' is optional, and 'date' is the timestamp of the data point
69+
push_data = [{"key": "sales2", "value": 100, "unit": "USD", "date": "2021-01-01T00:00:00Z" }]
8070

8171
try:
82-
api_instance.data_delete()
72+
api_instance.data_post(push_data=push_data)
8373
except ApiException as e:
84-
print("Exception when calling DefaultApi->data_delete: %s\n" % e)
85-
74+
# Handle exceptions that occur during the API call, such as invalid data or authentication issues
75+
pprint("API Exception occurred: %s\n" % e)
76+
except Exception as e:
77+
# Handle any other unexpected exceptions
78+
pprint("An unexpected error occurred: %s\n" % e)
79+
8680
```
87-
88-
## Documentation for API Endpoints
89-
90-
All URIs are relative to *https://push.databox.com*
91-
92-
Class | Method | HTTP request | Description
93-
------------ | ------------- | ------------- | -------------
94-
*DefaultApi* | [**data_delete**](docs/DefaultApi.md#data_delete) | **DELETE** /data |
95-
*DefaultApi* | [**data_metric_key_delete**](docs/DefaultApi.md#data_metric_key_delete) | **DELETE** /data/{metricKey} |
96-
*DefaultApi* | [**data_post**](docs/DefaultApi.md#data_post) | **POST** /data |
97-
*DefaultApi* | [**metrickeys_get**](docs/DefaultApi.md#metrickeys_get) | **GET** /metrickeys |
98-
*DefaultApi* | [**metrickeys_post**](docs/DefaultApi.md#metrickeys_post) | **POST** /metrickeys |
99-
*DefaultApi* | [**ping_get**](docs/DefaultApi.md#ping_get) | **GET** /ping |
100-
101-
102-
## Documentation For Models
103-
104-
- [ApiResponse](docs/ApiResponse.md)
105-
- [PushData](docs/PushData.md)
106-
- [PushDataAttribute](docs/PushDataAttribute.md)
107-
- [State](docs/State.md)
108-
109-
110-
<a id="documentation-for-authorization"></a>
111-
## Documentation For Authorization
112-
113-
114-
Authentication schemes defined for the API:
115-
<a id="basicAuth"></a>
116-
### basicAuth
117-
118-
- **Type**: HTTP basic authentication
119-
120-
121-
## Author
122-
123-
124-
125-

src/docs/ApiResponse.md

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)