Skip to content

Commit 434ba59

Browse files
Merge branch 'release-v5.5'
2 parents 1ad93bb + d2d5c48 commit 434ba59

12 files changed

Lines changed: 306 additions & 146 deletions

File tree

btrdb/__init__.py

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
## Imports
1616
##########################################################################
1717

18-
import os
1918
from btrdb.conn import Connection, BTrDB
2019
from btrdb.endpoint import Endpoint
21-
from btrdb.exceptions import ConnectionError, CredentialsFileNotFound, \
22-
ProfileNotFound
20+
from btrdb.exceptions import ConnectionError
2321
from btrdb.version import get_version
24-
from btrdb.utils.credentials import load_profile
22+
from btrdb.utils.credentials import credentials_by_profile, credentials
2523

2624
##########################################################################
2725
## Module Variables
@@ -37,8 +35,8 @@
3735
## Functions
3836
##########################################################################
3937

40-
def _connect(conn_str=None, apikey=None):
41-
return BTrDB(Endpoint(Connection(conn_str, apikey=apikey).channel))
38+
def _connect(endpoints=None, apikey=None):
39+
return BTrDB(Endpoint(Connection(endpoints, apikey=apikey).channel))
4240

4341
def connect(conn_str=None, apikey=None, profile=None):
4442
"""
@@ -64,39 +62,18 @@ def connect(conn_str=None, apikey=None, profile=None):
6462
An instance of the BTrDB context to directly interact with the database.
6563
6664
"""
67-
# Check function arguments
68-
65+
# do not allow user to provide both address and profile
6966
if conn_str and profile:
7067
raise ValueError("Received both conn_str and profile arguments.")
7168

69+
# use specific profile if requested
7270
if profile:
73-
credentials = load_profile(profile)
74-
return _connect(credentials["endpoints"], credentials["api_key"])
75-
76-
if conn_str:
77-
return _connect(conn_str, apikey)
78-
79-
# Check ENV variables
80-
81-
keys = os.environ.keys()
82-
if BTRDB_PROFILE in keys and BTRDB_ENDPOINTS in keys:
83-
raise ValueError("Found both BTRDB_PROFILE and BTRDB_ENDPOINTS in ENV. "
84-
"Only one is allowed.")
85-
86-
if BTRDB_PROFILE in keys:
87-
credentials = load_profile(os.environ[BTRDB_PROFILE])
88-
return _connect(credentials["endpoints"], credentials["api_key"])
71+
return _connect(**credentials_by_profile(profile))
8972

90-
if BTRDB_ENDPOINTS in keys:
91-
return _connect(os.environ[BTRDB_ENDPOINTS], os.environ.get(BTRDB_API_KEY, None))
92-
93-
94-
# Attempt default profile (no arguments or ENV found)
95-
96-
try:
97-
credentials = load_profile("default")
98-
return _connect(credentials["endpoints"], credentials["api_key"])
99-
except (CredentialsFileNotFound, ProfileNotFound):
100-
pass
73+
# resolve credentials using combination of arguments, env
74+
creds = credentials(conn_str, apikey)
75+
if "endpoints" in creds:
76+
return _connect(**creds)
10177

10278
raise ConnectionError("Could not determine credentials to use.")
79+

btrdb/conn.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545

4646

4747
class Connection(object):
48+
4849
def __init__(self, addrportstr, apikey=None):
49-
# type: () -> BTrDB
5050
"""
5151
Connects to a BTrDB server
5252
@@ -57,10 +57,6 @@ def __init__(self, addrportstr, apikey=None):
5757
apikey: str
5858
The option API key to authenticate requests
5959
60-
Returns
61-
-------
62-
Connection
63-
A Connection class object.
6460
"""
6561
addrport = addrportstr.split(":", 2)
6662
chan_ops = [('grpc.default_compression_algorithm', CompressionAlgorithm.gzip)]
@@ -110,7 +106,6 @@ class BTrDB(object):
110106
def __init__(self, endpoint):
111107
self.ep = endpoint
112108

113-
114109
def streams(self, *identifiers, versions=None):
115110
"""
116111
Returns a StreamSet object with BTrDB streams from the supplied
@@ -240,10 +235,10 @@ def streams_in_collection(self, *collection, is_collection_prefix=True, tags=Non
240235
annotations: Dict[str, str]
241236
The annotations to identify the stream.
242237
243-
Yields
238+
Returns
244239
------
245-
Stream Generator
246-
A stream generator that iterates over the search results.
240+
list
241+
A list of stream objects found with the provided search arguments.
247242
248243
"""
249244
result = []
@@ -269,7 +264,6 @@ def streams_in_collection(self, *collection, is_collection_prefix=True, tags=Non
269264
return result
270265

271266
def collection_metadata(self, prefix):
272-
# type: (csv.writer, QueryType, int, int, int, int, bool, *Tuple[int, str, UUID]) -> Tuple[Dict[str, int], Dict[str, int]]
273267
"""
274268
Gives statistics about metadata for collections that match a
275269
prefix.
@@ -279,6 +273,12 @@ def collection_metadata(self, prefix):
279273
prefix: str
280274
A prefix of the collection names to look at
281275
276+
Returns
277+
-------
278+
tuple
279+
A tuple of dictionaries containing metadata on the streams in the
280+
provided collection.
281+
282282
"""
283283
ep = self.ep
284284
tags, annotations = ep.getMetadataUsage(prefix)

btrdb/point.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,39 +152,42 @@ def time(self):
152152
The mean value of the time series point within a range of time
153153
"""
154154
return self._time
155+
155156
@property
156157
def min(self):
157158
"""
158159
The minimum value of the time series within a range of time
159160
"""
160161
return self._min
162+
161163
@property
162164
def mean(self):
163165
"""
164166
The mean value of the time series within a range of time
165167
"""
166168
return self._mean
169+
167170
@property
168171
def max(self):
169172
"""
170173
The maximum value of the time series within a range of time
171174
"""
172175
return self._max
176+
173177
@property
174178
def count(self):
175179
"""
176180
The number of values within the time series for a range of time
177181
"""
178182
return self._count
183+
179184
@property
180185
def stddev(self):
181186
"""
182187
The standard deviation of the values of a time series within a range of time
183188
"""
184189
return self._stddev
185190

186-
187-
188191
def __getitem__(self, index):
189192
if index == 0:
190193
return self.time

0 commit comments

Comments
 (0)