Skip to content

Commit 4c4c8f7

Browse files
committed
Initial import
1 parent 5ad1f07 commit 4c4c8f7

File tree

12 files changed

+333
-0
lines changed

12 files changed

+333
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.pyc
2+
*.py.swp
3+
.tox

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: python
2+
python:
3+
- "3.3"
4+
- "3.2"
5+
- "2.7"
6+
install:
7+
- "pip install -r requirements.txt --use-mirrors"
8+
- "pip install -r test-requirements.txt --use-mirrors"
9+
- "pip install --use-mirrors flake8 pep8-naming"
10+
script: nosetests && flake8 influxdb

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include requirements.txt
2+
include test-requirements.txt

influxdb/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# -*- coding: utf-8 -*-
2+
from influxdb.client import InfluxDBClient
3+
4+
5+
__all__ = ['InfluxDBClient']
6+
7+
__version__ = '0.1.0'

influxdb/client.py

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
python client for influxdb
4+
"""
5+
import requests
6+
import json
7+
8+
9+
class InfluxDBClient(object):
10+
"""
11+
InfluxDB Client
12+
"""
13+
def __init__(self, host, port, username, password, database):
14+
self._host = host
15+
self._port = port
16+
self._username = username
17+
self._password = password
18+
self._database = database
19+
self._baseurl = "http://{0}:{1}".format(self._host, self._port)
20+
21+
self._headers = json.dumps({
22+
'Content-type': 'application/json',
23+
'Accept': 'text/plain'})
24+
25+
# Change member variables
26+
27+
def switch_database(self, database):
28+
"""
29+
Change client database
30+
31+
Parameters
32+
----------
33+
database : string
34+
"""
35+
self._database = database
36+
37+
def switch_username(self, username, password):
38+
"""
39+
Change client username
40+
41+
Parameters
42+
----------
43+
username : string
44+
password : string
45+
"""
46+
self._username = username
47+
self._password = password
48+
49+
###
50+
# Administration & Security
51+
52+
###
53+
# Creating and Dropping Databases
54+
55+
def create_database(self, database):
56+
"""
57+
Create a database
58+
59+
Parameters
60+
----------
61+
database: string
62+
database name
63+
"""
64+
response = requests.post("{0}/db?u={1}&p={2}".format(
65+
self._baseurl,
66+
self._username,
67+
self._password),
68+
data=json.dumps({'name': database}),
69+
headers=self._headers)
70+
71+
if response.status_code == 200:
72+
return True
73+
else:
74+
raise Exception(response.content)
75+
76+
def delete_database(self, database):
77+
"""
78+
Drop a database
79+
80+
Parameters
81+
----------
82+
database: string
83+
database name
84+
"""
85+
response = requests.delete("{0}/db/{1}?u={2}&p={3}".format(
86+
self._baseurl,
87+
database,
88+
self._username,
89+
self._password))
90+
91+
if response.status_code == 200:
92+
return True
93+
else:
94+
raise Exception(response.content)
95+
96+
###
97+
# Security
98+
99+
###
100+
# Limiting User Access
101+
102+
def get_database_users(self):
103+
"""
104+
Get list of database users
105+
"""
106+
response = requests.get(
107+
"{0}/db/{1}/users?u={2}&p={3}".format(
108+
self._baseurl,
109+
self._database,
110+
self._username,
111+
self._password))
112+
113+
if response.status_code == 200:
114+
return True
115+
else:
116+
raise Exception(response.content)
117+
118+
def add_database_user(self, new_username, new_password):
119+
"""
120+
Add database user
121+
"""
122+
response = requests.post(
123+
"{0}/db/{1}/users?u={2}&p={3}".format(
124+
self._baseurl,
125+
self._database,
126+
self._username,
127+
self._password),
128+
data=json.dumps({
129+
'username': new_username,
130+
'password': new_password}),
131+
headers=self._headers)
132+
133+
if response.status_code == 200:
134+
return True
135+
else:
136+
raise Exception(response.content)
137+
138+
def update_database_password(self, username, new_password):
139+
"""
140+
Update password
141+
"""
142+
response = requests.post(
143+
"{0}/db/{1}/users/{2}?u={3}&p={4}".format(
144+
self._baseurl,
145+
self._database,
146+
username,
147+
self._username,
148+
self._password),
149+
data=json.dumps({
150+
'password': new_password}),
151+
headers=self._headers)
152+
153+
if response.status_code == 200:
154+
if username == self._username:
155+
self._password = new_password
156+
return True
157+
else:
158+
raise Exception(response.content)
159+
160+
def delete_database_user(self, username):
161+
"""
162+
Delete database user
163+
"""
164+
response = requests.delete(
165+
"{0}/db/{1}/users/{2}?u={3}&p={4}".format(
166+
self._baseurl,
167+
self._database,
168+
username,
169+
self._username,
170+
self._password))
171+
172+
if response.status_code == 200:
173+
return True
174+
else:
175+
raise Exception(response.content)
176+
177+
###
178+
# Writing Data
179+
180+
def write_points(self, data):
181+
"""
182+
Write to multiple time series names
183+
"""
184+
response = requests.post(
185+
"{0}/db/{1}/series?u={2}&p={3}".format(
186+
self._baseurl,
187+
self._database,
188+
self._username,
189+
self._password),
190+
data=json.dumps(data),
191+
headers=self._headers)
192+
193+
if response.status_code == 200:
194+
return True
195+
else:
196+
raise Exception(response.content)
197+
198+
def write_points_with_time_precision(self, data, time_precision='s'):
199+
"""
200+
Write to multiple time series names
201+
"""
202+
if time_precision not in ['s', 'm', 'u']:
203+
raise Exception("Invalid time precision is given.")
204+
205+
response = requests.post(
206+
"{0}/db/{1}/series?u={2}&p={3}&time_precision={4}".format(
207+
self._baseurl,
208+
self._database,
209+
self._username,
210+
self._password,
211+
time_precision),
212+
data=json.dumps(data),
213+
headers=self._headers)
214+
215+
if response.status_code == 200:
216+
return True
217+
else:
218+
raise Exception(response.content)
219+
220+
def delete_points(self, name,
221+
regex=None, start_epoch=None, end_epoch=None):
222+
pass
223+
224+
###
225+
# Regularly Scheduled Deletes
226+
227+
###
228+
# Querying Data

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests

setup.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
try:
5+
import distribute_setup
6+
distribute_setup.use_setuptools()
7+
except:
8+
pass
9+
10+
try:
11+
from setuptools import setup, find_packages
12+
except ImportError:
13+
from distutils.core import setup
14+
15+
import os
16+
import re
17+
18+
19+
with open(os.path.join(os.path.dirname(__file__),
20+
'influxdb', '__init__.py')) as f:
21+
version = re.search("__version__ = '([^']+)'", f.read()).group(1)
22+
23+
with open('requirements.txt', 'r') as f:
24+
requires = [x.strip() for x in f if x.strip()]
25+
26+
with open('test-requirements.txt', 'r') as f:
27+
test_requires = [x.strip() for x in f if x.strip()]
28+
29+
setup(
30+
name='influxdb',
31+
version=version,
32+
description="influxdb client",
33+
packages=find_packages(exclude=['tests']),
34+
test_suite='tests',
35+
tests_require=test_requires,
36+
install_requires=requires,
37+
extras_require={'test': test_requires},
38+
)

test-requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
nose
2+
mock

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- coding: utf-8 -*-

tests/influxdb/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- coding: utf-8 -*-

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy