summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gevers <elbrus@debian.org>2022-09-15 21:57:44 +0200
committerPaul Gevers <elbrus@debian.org>2022-09-15 21:57:44 +0200
commitcfd16fb84dd9b1007ec5ec2f1c5abae7b648d8a5 (patch)
tree48c43cf1219602acb081b3912db300a9778b65f6
parenta3ca1790e852fd0d9957d16d28daf88756609e8b (diff)
parent7b9336f02fc2f738bbfa1fafe9f04f34277d579b (diff)
Update upstream source from tag 'upstream/2.0.8'
Update to upstream version '2.0.8' with Debian dir 6c5178c447532d26af12a901fd07275d93cbf4a3
-rw-r--r--.gitignore2
-rw-r--r--ChangeLog9
-rw-r--r--README.md166
-rw-r--r--dist/siridb-connector-2.0.1.tar.gzbin9006 -> 0 bytes
-rw-r--r--dist/siridb-connector-2.0.2.tar.gzbin9063 -> 0 bytes
-rw-r--r--dist/siridb-connector-2.0.3.tar.gzbin9164 -> 0 bytes
-rw-r--r--dist/siridb-connector-2.0.4.tar.gzbin8798 -> 0 bytes
-rw-r--r--setup.py28
-rw-r--r--siridb/__init__.py4
-rw-r--r--siridb/connector/__init__.py15
-rw-r--r--siridb/connector/lib/__init__.py2
-rw-r--r--siridb/connector/lib/client.py11
-rw-r--r--siridb/connector/lib/connection.py14
-rw-r--r--siridb/connector/lib/constants.py4
-rw-r--r--siridb/connector/lib/defaults.py2
-rw-r--r--siridb/connector/lib/exceptions.py3
-rw-r--r--siridb/connector/lib/logging.py3
-rw-r--r--siridb/connector/lib/protocol.py7
-rw-r--r--siridb/connector/lib/protomap.py2
19 files changed, 239 insertions, 33 deletions
diff --git a/.gitignore b/.gitignore
index 33a0e53..b6742b0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,5 @@ __pycache__/
checklist.txt
test/
build/
+dist/
+siridb_connector.egg-info/
diff --git a/ChangeLog b/ChangeLog
index c49864f..0871bc5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2021.03.17, Version 2.0.7 (BETA)
+
+ - Using `siridb.connector` logger.
+
+2021.03.15, Version 2.0.6 (BETA)
+
+ - Added `connected` property to client.
+ - Added time precision constants.
+
2017.03.09, Version 2.0.5 (BETA)
- Raise Authentication Errors on connect.
diff --git a/README.md b/README.md
index df7037a..6b63435 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,27 @@
SiriDB - Connector
==================
-This manual describes how to install and configure SiriDB Connector for Python 3, a self-contained Python driver for communicating with SiriDB servers, and how to use it to develop database applications.
+The SiriDB Connector is a self-contained Python driver for communicating with SiriDB servers.
+This manual describes how to install and configure SiriDB Connector for Python 3, and how to use it to develop database applications.
-Installation
+---------------------------------------
+ * [Installation](#installation)
+ * [Quick usage](#quick-usage)
+ * [SiriDBClient](#siridbclient)
+ * [connect](#siridbclientconnect)
+ * [insert](#siridbclientinsert)
+ * [query](#siridbclientquery)
+ * [close](#siridbclientclose)
+ * [Exception codes](#exception-codes)
+ * [Version info](#version-info)
+
+---------------------------------------
+
+## Installation
------------
-From PyPI (recommend)
+From PyPI (recommended)
```
pip install siridb-connector
@@ -19,23 +33,33 @@ From source code
python setup.py install
```
-Example
+
+## Quick usage
-------
```python
import asyncio
+import time
+import random
from siridb.connector import SiriDBClient
async def example(siri):
# Start connecting to SiriDB.
# .connect() returns a list of all connections referring to the supplied
# hostlist. The list can contain exceptions in case a connection could not
- # be made.
+ # be made.
await siri.connect()
-
+
try:
- resp = await siri.query('show')
+ # insert
+ ts = int(time.time())
+ value = random.random()
+ await siri.insert({'some_measurement': [[ts, value]]})
+
+ # query
+ resp = await siri.query('select * from "some_measurement"')
print(resp)
+
finally:
# Close all SiriDB connections.
siri.close()
@@ -51,3 +75,131 @@ siri = SiriDBClient(
loop = asyncio.get_event_loop()
loop.run_until_complete(example(siri))
```
+
+
+## SiriDBClient
+Create a new SiriDB Client. This creates a new client but `.connect()` must be used to connect.
+
+```python
+siri = SiriDBClient(
+ username=<username>,
+ password=<password>,
+ dbname=<dbname>,
+ hostlist=[(<host>, <port>, {weight: 1}, {backup: False})],
+ loop=None,
+ keepalive=True,
+ timeout=10,
+ inactive_time=30,
+ max_wait_retry=90)
+```
+
+Arguments:
+* __username__: User with permissions to use the database.
+* __password__: Password for the given username.
+* __dbname__: Name of the database.
+* __hostlist__: List with SiriDB servers (all servers or a subset of
+servers can be in this list).
+
+
+ *Example:*
+ ```python
+ hostlist=[ ('server1.local', 9000, {'weight': 3}),
+ ('server2.local', 9001),
+ ('backup1.local', 9002, {'backup': True}) ]
+ ```
+ Each server should at least have a hostname and port
+ number. Optionally you can provide a dictionary with
+ extra options.
+
+ Available Options:
+ - __weight__ : Should be a value between 1 and 9. A higher
+ value gives the server more weight so it will
+ be more likely chosen. (default 1)
+ - __backup__ : Should be either True or False. When True the
+ server will be marked as backup server and
+ will only be chosen if no other server is
+ available. (default: False)
+
+
+Keyword arguments:
+* __loop__: Asyncio loop. When 'None' the default event loop will be used.
+* __keepalive__: When 'True' keep-alive packages are send every 45 seconds.
+* __timeout__: Maximum time to complete a process, otherwise it will be cancelled.
+* __inactive_time__: When a server is temporary unavailable, for
+example the server could be paused, we mark the server as inactive after x seconds.
+* __max_wait_retry__: When the reconnect loop starts, we try to reconnect in 1 second, then 2 seconds, 4, 8 and so on until max_wait_retry is reached and then use this value to retry again.
+******************************************************************************
+
+### SiriDBClient.connect
+
+Start connecting to SiriDB. `.connect()` returns a list of all connections referring to the supplied hostlist. The list can contain exceptions in case a connection could not be made.
+
+Optionally the keyword argument `timeout` can be set. This will constrain the search time for a connection. Exceeding the timeout will raise an `.TimeoutError`.
+
+```python
+siri.connect(timeout=None)
+```
+
+### SiriDBClient.insert
+
+Insert time series data into SiriDB. Requires a 'dictionary' with at least one series.
+Optionally the `timeout` can be adjusted (default: 300).
+
+```python
+siri.insert(data, timeout=300)
+```
+
+### SiriDBClient.query
+
+Query data out of the database. Requires a string containing the query. More about the query language can be found [here](https://siridb.net/documentation/). The documentation about the query language will inform you about a number of useful aggregation and filter functions, different ways of visualizing and grouping the requested data, and how to make changes to the set up of the database. Optionally a `time_precision` (`SECOND`, `MICROSECOND`, `MILLISECOND`, `NANOSECOND`) can be set. The default `None` sets the precision to seconds. Futhermore the `timeout` can be adjusted (default: 60).
+
+```python
+from siridb.connector import (SECOND,
+ MICROSECOND,
+ MILLISECOND,
+ NANOSECOND)
+
+siri.query(query, time_precision=None, timeout=60)
+```
+
+### SiriDBClient.close
+
+Close the connection.
+
+```python
+siri.close()
+```
+
+Check if the connection is closed.
+
+```python
+siri.is_closed
+```
+
+## Exception codes
+
+The following exceptions can be returned:
+
+- `AuthenticationError`:
+ *Raised when credentials are invalid or insufficient.*
+- `IndexError`:
+*Raised when the database does not exist (anymore).*
+- `InsertError` (can only be raised when using the `.insert()` method):
+ *Make sure the data is correct because this only happens when SiriDB could not process the request.*
+- `OverflowError` (can only be raised when using the `.insert()` method):
+ *Raised when integer values cannot not be packed due to an overflow error (integer values should be signed and not more than 63 bits).*
+- `PoolError`:
+ *SiriDB has no online server for at least one required pool. Try again later after some reasonable delay.*
+- `QueryError` (can only be raised when using the `.query()` method):
+ *Make sure the query is correct because this only happens when SiriDB could not process the query. Consult the [documentation](https://siridb.net/documentation/#help_select) about the query language can be found.*
+- `RuntimeError`:
+ *Raised when a general error message is received. This should no happen unless a new bug is discovered.*
+- `ServerError`:
+ *Raised when a server could not perform the request, you could try another server if one is available. Consult the [documentation](https://siridb.net/documentation/#help_list_servers) how to get additional status information about the servers.*
+- `TimeoutError`:
+ *Raised when a process lasts longer than the `timeout` period*
+- `TypeError`:
+ *Raised when an unknown package is received (might be caused by running a different SiriDB version).*
+- `UserAuthError`:
+ *The user as no rights to perform the insert or query. Consult the [documentation](https://siridb.net/documentation/#help_access) how to change the access rights.*
+
diff --git a/dist/siridb-connector-2.0.1.tar.gz b/dist/siridb-connector-2.0.1.tar.gz
deleted file mode 100644
index c29326c..0000000
--- a/dist/siridb-connector-2.0.1.tar.gz
+++ /dev/null
Binary files differ
diff --git a/dist/siridb-connector-2.0.2.tar.gz b/dist/siridb-connector-2.0.2.tar.gz
deleted file mode 100644
index 142a857..0000000
--- a/dist/siridb-connector-2.0.2.tar.gz
+++ /dev/null
Binary files differ
diff --git a/dist/siridb-connector-2.0.3.tar.gz b/dist/siridb-connector-2.0.3.tar.gz
deleted file mode 100644
index 504b992..0000000
--- a/dist/siridb-connector-2.0.3.tar.gz
+++ /dev/null
Binary files differ
diff --git a/dist/siridb-connector-2.0.4.tar.gz b/dist/siridb-connector-2.0.4.tar.gz
deleted file mode 100644
index 234f323..0000000
--- a/dist/siridb-connector-2.0.4.tar.gz
+++ /dev/null
Binary files differ
diff --git a/setup.py b/setup.py
index 5d9d891..e1157ba 100644
--- a/setup.py
+++ b/setup.py
@@ -1,7 +1,22 @@
+"""
+Upload to PyPI
+
+python setup.py sdist
+twine upload --repository pypitest dist/siridb-connector-X.X.X.tar.gz
+twine upload --repository pypi dist/siridb-connector-X.X.X.tar.gz
+"""
+
from distutils.core import setup
import setuptools
+from siridb import __version__
+
+
+VERSION = __version__
+
+
+with open('README.md', 'r') as f:
+ long_description = f.read()
-VERSION = '2.0.5'
setup(
name='siridb-connector',
@@ -11,12 +26,13 @@ setup(
'siridb.connector.lib'],
version=VERSION,
description='SiriDB Connector',
+ long_description=long_description,
+ long_description_content_type='text/markdown',
author='Jeroen van der Heijden',
author_email='jeroen@transceptor.technology',
- url='https://github.com/transceptor-technology/siridb-connector',
- download_url=
- 'https://github.com/transceptor-technology/'
- 'siridb-connector/tarball/{}'.format(VERSION),
+ url='https://github.com/SiriDB/siridb-connector',
+ download_url='https://github.com/SiriDB/'
+ 'siridb-connector/tarball/{}'.format(VERSION),
keywords=['siridb', 'connector', 'database', 'client'],
classifiers=[
'Development Status :: 4 - Beta',
@@ -28,6 +44,8 @@ setup(
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
+ 'Programming Language :: Python :: 3.7',
+ 'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3 :: Only',
'Topic :: Database',
'Topic :: Software Development'
diff --git a/siridb/__init__.py b/siridb/__init__.py
index e69de29..91c560b 100644
--- a/siridb/__init__.py
+++ b/siridb/__init__.py
@@ -0,0 +1,4 @@
+__version_info__ = (2, 0, 8)
+__version__ = '.'.join(map(str, __version_info__))
+__maintainer__ = 'Jeroen van der Heijden'
+__email__ = 'jeroen@transceptor.technology'
diff --git a/siridb/connector/__init__.py b/siridb/connector/__init__.py
index cc88a3b..60a71e9 100644
--- a/siridb/connector/__init__.py
+++ b/siridb/connector/__init__.py
@@ -6,18 +6,21 @@ from .lib.protocol import _SiriDBInfoProtocol
from .lib.connection import SiriDBConnection
from .lib.defaults import DEFAULT_CLIENT_PORT
from .lib.client import SiriDBClient
+from .lib.constants import SECOND
+from .lib.constants import MICROSECOND
+from .lib.constants import MILLISECOND
+from .lib.constants import NANOSECOND
-
-__version_info__ = (2, 0, 5)
-__version__ = '.'.join(map(str, __version_info__))
-__maintainer__ = 'Jeroen van der Heijden'
-__email__ = 'jeroen@transceptor.technology'
__all__ = [
'async_connect',
'async_server_info',
'connect',
'SiriDBClient',
'SiriDBProtocol',
+ 'SECOND',
+ 'MICROSECOND',
+ 'MILLISECOND',
+ 'NANOSECOND'
]
@@ -93,5 +96,3 @@ async def async_server_info(host='127.0.0.1',
result = await protocol.future
transport.close()
return result
-
-
diff --git a/siridb/connector/lib/__init__.py b/siridb/connector/lib/__init__.py
index bf26a99..26b2ff3 100644
--- a/siridb/connector/lib/__init__.py
+++ b/siridb/connector/lib/__init__.py
@@ -2,4 +2,4 @@
:copyright: 2017, Jeroen van der Heijden (Transceptor Technology)
:license: MIT
-''' \ No newline at end of file
+'''
diff --git a/siridb/connector/lib/client.py b/siridb/connector/lib/client.py
index b3ec636..09044a2 100644
--- a/siridb/connector/lib/client.py
+++ b/siridb/connector/lib/client.py
@@ -6,13 +6,13 @@ SiriDB Client for python => 3.5 using asyncio.
'''
import asyncio
import functools
-import logging
import random
from .protocol import _SiriDBProtocol
from .connection import SiriDBAsyncConnection
from .exceptions import AuthenticationError
from .exceptions import ServerError
from .exceptions import PoolError
+from .logging import logger as logging
class _SiriDBClientProtocol(_SiriDBProtocol):
@@ -164,6 +164,11 @@ class SiriDBClient:
'''Can be used to check if close() has been called.'''
return not self._retry_connect
+ @property
+ def connected(self):
+ '''Can be used to check the client has any active connections'''
+ return any(connection.connected for connection in self._connections)
+
@staticmethod
def _log_connect_result(result):
for r in result:
@@ -225,7 +230,7 @@ class SiriDBClient:
# only try unavailable once
try_unavailable = False
- async def _connect(self, timeout=None):
+ async def _connect(self, timeout=None): # the one that actually connects
tasks = [
connection.connect(
self._username,
@@ -247,7 +252,7 @@ class SiriDBClient:
self._log_connect_result(result)
return result
- async def _connect_loop(self):
+ async def _connect_loop(self): # the one that looks for connections
sleep = 1
try:
while [connection
diff --git a/siridb/connector/lib/connection.py b/siridb/connector/lib/connection.py
index dbab4dd..70fa7e1 100644
--- a/siridb/connector/lib/connection.py
+++ b/siridb/connector/lib/connection.py
@@ -1,6 +1,5 @@
import asyncio
import time
-import logging
from .defaults import DEFAULT_CLIENT_PORT
from .protocol import _SiriDBProtocol
from .protomap import CPROTO_REQ_QUERY
@@ -8,6 +7,11 @@ from .protomap import CPROTO_REQ_INSERT
from .protomap import CPROTO_REQ_REGISTER_SERVER
from .protomap import CPROTO_REQ_PING
from .protomap import FILE_MAP
+from .constants import SECOND
+from .constants import MICROSECOND
+from .constants import MILLISECOND
+from .constants import NANOSECOND
+from .logging import logger as logging
class SiriDBConnection():
@@ -152,6 +156,12 @@ class SiriDBAsyncConnection():
del self._protocol
async def query(self, query, time_precision=None, timeout=3600):
+ assert time_precision in (
+ None,
+ SECOND,
+ MICROSECOND,
+ MILLISECOND,
+ NANOSECOND), 'time_precision must be either None, 0, 1, 2, 3'
result = await self._protocol.send_package(
CPROTO_REQ_QUERY,
data=(query, time_precision),
@@ -169,4 +179,4 @@ class SiriDBAsyncConnection():
@property
def connected(self):
- return self._protocol is not None and self._protocol._connected \ No newline at end of file
+ return self._protocol is not None and self._protocol._connected
diff --git a/siridb/connector/lib/constants.py b/siridb/connector/lib/constants.py
new file mode 100644
index 0000000..ebde374
--- /dev/null
+++ b/siridb/connector/lib/constants.py
@@ -0,0 +1,4 @@
+SECOND = 0
+MILLISECOND = 1
+MICROSECOND = 2
+NANOSECOND = 3
diff --git a/siridb/connector/lib/defaults.py b/siridb/connector/lib/defaults.py
index d6a407e..0e74a60 100644
--- a/siridb/connector/lib/defaults.py
+++ b/siridb/connector/lib/defaults.py
@@ -1,4 +1,4 @@
'''SiriDB Default values
'''
-DEFAULT_CLIENT_PORT = 9000 \ No newline at end of file
+DEFAULT_CLIENT_PORT = 9000
diff --git a/siridb/connector/lib/exceptions.py b/siridb/connector/lib/exceptions.py
index 66c087b..16ae148 100644
--- a/siridb/connector/lib/exceptions.py
+++ b/siridb/connector/lib/exceptions.py
@@ -3,6 +3,7 @@
:copyright: 2016, Jeroen van der Heijden (Transceptor Technology)
'''
+
class QueryError(Exception):
pass
@@ -25,5 +26,3 @@ class AuthenticationError(Exception):
class UserAuthError(AuthenticationError):
pass
-
-
diff --git a/siridb/connector/lib/logging.py b/siridb/connector/lib/logging.py
new file mode 100644
index 0000000..a19ad58
--- /dev/null
+++ b/siridb/connector/lib/logging.py
@@ -0,0 +1,3 @@
+import logging
+
+logger = logging.getLogger('siridb.connector')
diff --git a/siridb/connector/lib/protocol.py b/siridb/connector/lib/protocol.py
index c764cc2..b0e1ff8 100644
--- a/siridb/connector/lib/protocol.py
+++ b/siridb/connector/lib/protocol.py
@@ -3,7 +3,6 @@
:copyright: 2016, Jeroen van der Heijden (Transceptor Technology)
'''
import asyncio
-import logging
import qpack
from . import protomap
from .datapackage import DataPackage
@@ -13,6 +12,7 @@ from .exceptions import ServerError
from .exceptions import PoolError
from .exceptions import AuthenticationError
from .exceptions import UserAuthError
+from .logging import logger as logging
_MAP = (
@@ -21,6 +21,7 @@ _MAP = (
lambda data: data
)
+
def _packdata(tipe, data=None):
assert tipe in protomap.MAP_REQ_DTYPE, \
'No data type found for message type: {}'.format(tipe)
@@ -64,7 +65,8 @@ class _SiriDBProtocol(asyncio.Protocol):
protomap.CPROTO_ERR_AUTH_UNKNOWN_DB: lambda f, d: f.set_exception(
AuthenticationError('Unknown database')),
protomap.CPROTO_ERR_LOADING_DB: lambda f, d: f.set_exception(
- RuntimeError('Error loading database, '
+ RuntimeError(
+ 'Error loading database, '
'please check the SiriDB log files')),
protomap.CPROTO_ERR_FILE: lambda f, d: f.set_exception(
RuntimeError('Error retreiving file')),
@@ -85,7 +87,6 @@ class _SiriDBProtocol(asyncio.Protocol):
override asyncio.Protocol
'''
-
self._connected = True
self.transport = transport
diff --git a/siridb/connector/lib/protomap.py b/siridb/connector/lib/protomap.py
index 8290fd3..ad360fc 100644
--- a/siridb/connector/lib/protomap.py
+++ b/siridb/connector/lib/protomap.py
@@ -124,5 +124,3 @@ FILE_MAP = {
'users.dat': CPROTO_REQ_FILE_USERS,
'groups.dat': CPROTO_REQ_FILE_GROUPS
}
-
-