Skip to content

Commit 2f53498

Browse files
committed
Add an example script
1 parent 9bae5a4 commit 2f53498

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

examples/tutorial.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import argparse
2+
3+
from influxdb import InfluxDBClient
4+
5+
6+
def main(host=None, port=None):
7+
user = 'root'
8+
password = 'root'
9+
dbname = 'example'
10+
dbuser = 'smly'
11+
dbuser_password = 'my_secret_password'
12+
query = 'select column_one from foo;'
13+
json_body = [
14+
{
15+
"points": [
16+
["1", 1, 1.0],
17+
["2", 2, 2.0]
18+
],
19+
"name": "foo",
20+
"columns": ["column_one", "column_two", "column_three"]
21+
}
22+
]
23+
24+
25+
client = InfluxDBClient(host, port, user, password, dbname)
26+
27+
print("Create database: " + dbname)
28+
client.create_database(dbname)
29+
30+
dbusers = client.get_database_users()
31+
print("Get list of database users: {0}".format(dbusers))
32+
33+
print("Add database user: " + dbuser)
34+
client.add_database_user(dbuser, dbuser_password)
35+
36+
dbusers = client.get_database_users()
37+
print("Get list of database users again: {0}".format(dbusers))
38+
39+
print("Swtich user: " + dbuser)
40+
client.switch_user(dbuser, dbuser_password)
41+
42+
print("Write points: {0}".format(json_body))
43+
client.write_points(json_body)
44+
45+
print("Queying data: " + query)
46+
result = client.query(query)
47+
48+
print("Result: {0}".format(result))
49+
50+
print("Swtich user: " + user)
51+
client.switch_user(user, password)
52+
53+
print("Delete database: " + dbname)
54+
client.delete_database(dbname)
55+
56+
57+
def parse_args():
58+
parser = argparse.ArgumentParser(
59+
description='example code to play with InfluxDB')
60+
parser.add_argument('--host', type=str, required=True)
61+
parser.add_argument('--port', type=int, required=True)
62+
return parser.parse_args()
63+
64+
65+
if __name__ == '__main__':
66+
args = parse_args()
67+
main(host=args.host, port=args.port)

influxdb/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
__all__ = ['InfluxDBClient']
66

7-
__version__ = '0.1.0'
7+
__version__ = '0.1.1'

0 commit comments

Comments
 (0)