etcdb package¶
Subpackages¶
Submodules¶
etcdb.cli module¶
Command line functions
etcdb.connection module¶
Connection class definition
etcdb.cursor module¶
-
class
etcdb.cursor.
Cursor
(connection)[source]¶ Bases:
object
These objects represent a database cursor, which is used to manage the context of a fetch operation. Cursors created from the same connection are not isolated, i.e. , any changes done to the database by a cursor are immediately visible by the other cursors. Cursors created from different connections can or can not be isolated, depending on how the transaction support is implemented (see also the connection’s .rollback () and .commit () methods).
-
arraysize
= 1¶ This read/write attribute specifies the number of rows to fetch at a time with .fetchmany(). It defaults to 1 meaning to fetch a single row at a time.
-
connection
= None¶ Etcd connection object
-
description
= None¶ This read-only attribute is a sequence of 7-item sequences.
Each of these sequences contains information describing one result column:
name type_code display_size internal_size precision scale null_okThe first two items ( name and type_code ) are mandatory, the other five are optional and are set to None if no meaningful values can be provided.
-
execute
(query, args=None)[source]¶ Prepare and execute a database operation (query or command).
Parameters: - query (str) – Query text.
- args (tuple) – Optional query arguments.
Raises: - ProgrammingError – if query can’t be parsed.
- InternalError – If etcd is not ready to serve request
-
static
executemany
(operation, **kwargs)[source]¶ Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters .
-
fetchall
()[source]¶ Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e.g. a list of tuples). Note that the cursor’s arraysize attribute can affect the performance of this operation.
-
fetchmany
(n)[source]¶ Fetch the next set of rows of a query result, returning a sequence of sequences (e.g. a list of tuples). An empty sequence is returned when no more rows are available.
-
fetchone
()[source]¶ Fetch the next row of a query result set, returning a single sequence, or None when no more data is available.
-
static
morgify
(query, args)[source]¶ Prepare query string that will be sent to parser
Parameters: - query – Query text
- args – Tuple with query arguments
Returns: Query text
Return type: str
-
n_cols
¶
-
n_rows
¶
-
result_set
¶
-
rowcount
¶
-
etcdb.etcddate module¶
etcdb.etcdstring module¶
etcdb.etcdtime module¶
etcdb.etcdtimestamp module¶
etcdb.eval_expr module¶
Module provides functions to evaluate an expression given in a WHERE statement. Grammar of expression is described on MySQL website (https://dev.mysql.com/doc/refman/5.7/en/expressions.html).
-
class
etcdb.eval_expr.
EtcdbFunction
(*args, **kwargs)[source]¶ Bases:
object
EtcdbFunction represents an SQL function.
Parameters: - function_name (callable) – python function that implements SQL function.
- group (bool) – True if the functions is aggregate function
- args – Arguments to pass to function_name
- kwargs – Keyword arguments
-
function
¶ Return function name
-
group
¶ Return whether the function is aggregate
-
etcdb.eval_expr.
etcdb_count
(result_set)[source]¶ Count rows in result set
Parameters: result_set (ResultSet) – ResultSet instance Returns: number of rows in ResultSet Return type: int
-
etcdb.eval_expr.
eval_expr
(row, tree)[source]¶ Evaluate expression
Returns: Tuple with string representation and value. For example, (‘id’, 5). Return type: tuple
-
etcdb.eval_expr.
eval_function_call
(row, tree)[source]¶ Evaluate function call :return: tuple with field name and EtcdbFunction instance
etcdb.exception module¶
etcdb exceptions
-
exception
etcdb.exception.
DataError
[source]¶ Bases:
etcdb.exception.DatabaseError
Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range, etc.
-
exception
etcdb.exception.
DatabaseError
[source]¶ Bases:
etcdb.exception.Error
Exception raised for errors that are related to the database.
-
exception
etcdb.exception.
Error
[source]¶ Bases:
exceptions.Exception
Exception that is the base class of all other error exceptions.
-
exception
etcdb.exception.
IntegrityError
[source]¶ Bases:
etcdb.exception.DatabaseError
Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails.
-
exception
etcdb.exception.
InterfaceError
[source]¶ Bases:
etcdb.exception.Error
Exception raised for errors that are related to the database interface rather than the database itself.
-
exception
etcdb.exception.
InternalError
[source]¶ Bases:
etcdb.exception.DatabaseError
Exception raised when the database encounters an internal error, e.g. the cursor is not valid anymore, the transaction is out of sync, etc.
-
exception
etcdb.exception.
NotSupportedError
[source]¶ Bases:
etcdb.exception.DatabaseError
Exception raised in case a method or database API was used which is not supported by the database, e.g. requesting a .rollback() on a connection that does not support transaction or has transactions turned off.
-
exception
etcdb.exception.
OperationalError
[source]¶ Bases:
etcdb.exception.DatabaseError
Exception raised for errors that are related to the database’s operation and not necessarily under the control of the programmer, e.g. an unexpected disconnect occurs, the data source name is not found, a transaction could not be processed, a memory allocation error occurred during processing, etc.
-
exception
etcdb.exception.
ProgrammingError
[source]¶ Bases:
etcdb.exception.DatabaseError
Exception raised for programming errors, e.g. table not found or already exists, syntax error in the SQL statement, wrong number of parameters specified, etc.
etcdb.lock module¶
Locking for etcdb
etcdb implements MyISAM style locking. There is an exclusive writer lock and there are many shared reader locks. A client can acquire a writer lock if there are no readers and no writers. A client can acquire a reader lock if there are no writers.
-
class
etcdb.lock.
Lock
(etcd_client, db, tbl, **kwargs)[source]¶ Bases:
object
Instantiate Lock instance for a table.
Parameters: - etcd_client (Client) – Etcd client
- db – Database name.
- tbl – Table name.
-
acquire
(timeout=50, ttl=50, **kwargs)[source]¶ Get a lock
Parameters: - timeout (int) – Timeout to acquire a lock.
- ttl (int) – Place a lock on this time in seconds. 0 for permanent lock.
- kwargs –
Keyword arguments.
- author (
str
) - Who requests the lock. - By default, ‘etcdb’.
- author (
- reason (
str
) - Human readable reason to get the lock. - By default, ‘etcdb internal operation’.
- reason (
Raises: - InternalError – This class shouldn’t be used directly and if user doesn’t set lock_prefix the method should raise exception.
- OperationalError – If lock wait timeout expires.
Returns: String that identifies who acquired the lock. Return type: str
-
created_at
¶ Returns: When the lock was acquired in Unix timestamp. Return type: int
-
id
¶ Lock identifier
-
readers
()[source]¶ Get list of reader locks.
Returns: List of ReadLock() instances Return type: list(ReadLock)
-
reason
¶ Returns: String that explains why lock was acquired. Return type: str
-
class
etcdb.lock.
MetaLock
(etcd_client, db, tbl)[source]¶ Bases:
etcdb.lock.Lock
Meta lock is needed to place a read or write lock.
-
class
etcdb.lock.
ReadLock
(etcd_client, db, tbl, lock_id=None)[source]¶ Bases:
etcdb.lock.Lock
Read lock.
-
class
etcdb.lock.
WriteLock
(etcd_client, db, tbl, lock_id=None)[source]¶ Bases:
etcdb.lock.Lock
Write lock.
etcdb.resultset module¶
Classes that represent query results
-
class
etcdb.resultset.
Column
(colname, coltype=None, options=None)[source]¶ Bases:
object
Instantiate a Column
Parameters: - colname (str) – Column name.
- coltype (str) – Column type
- options (ColumnOptions) – Column options
-
auto_increment
¶ True if column is auto_incrementing.
-
default
¶ Column default value.
-
name
¶ Column name
-
nullable
¶ True if column is NULL-able.
-
primary
¶ True if column is primary key.
-
print_width
¶ How many symbols client has to spare to print column value. A column name can be short, but its values may be longer. To align column and its values print_width is number of characters a client should allocate for the column name so it will be as lager as the largest columns length value.
-
type
¶ Column type e.g. INT, VARCHAR, etc.
-
unique
¶ True if column is unique key.
-
class
etcdb.resultset.
ColumnOptions
(*options, **kwoptions)[source]¶ Bases:
object
ColumnOptions represents column options like NULL-able or not
-
auto_increment
= False¶
-
default
= None¶
-
nullable
= None¶
-
primary
= False¶
-
unique
= None¶
-
-
class
etcdb.resultset.
ColumnSet
(columns=None)[source]¶ Bases:
object
Instantiate a Column set
Parameters: columns (dict) – Optional dictionary with column definitions -
add
(column)[source]¶ Add column to ColumnSet
Parameters: column (Column) – Column instance Returns: Updated CoulmnSet instance Return type: ColumnSet
-
columns
¶ Returns list of Columns
-
empty
¶ True if there are no columns in the ColumnSet
-
primary
¶ Return primary key column
-
-
class
etcdb.resultset.
ResultSet
(columns, rows=None)[source]¶ Bases:
object
Represents query result
Parameters: -
add_row
(row)[source]¶ Add row to result set
Parameters: row (Row) – Row instance Returns: Updated result set Return type: ResultSet Raises: InternalError – if row is not a Row class instance.
-
n_cols
¶ Return number of columns in the result set.
-
n_rows
¶ Return number of rows in the result set.
-
-
class
etcdb.resultset.
Row
(row, etcd_index=0, modified_index=0)[source]¶ Bases:
object
Row class
Parameters: row (tuple) – Row values -
etcd_index
¶ A row in etcdb is a key. Etcd index corresponds to X-Etcd-Index in etcd response header.
Returns: Etcd index. Return type: int
-
modified_index
¶ modifiedIndex of a key in etcd
-
row
¶ Returns: Return tuple with row values.. Return type: tuple
-
Module contents¶
PEP-249 implementation for etcd
-
etcdb.
Binary
(string)[source]¶ This function constructs an object capable of holding a binary (long) string value.
-
etcdb.
Date
(year, month, day)[source]¶ This function constructs an object holding a date value.
Parameters: - year – Year, e.g. 2016
- month – Month, e.g. 9
- day – Day, e.g. 21
Returns: EtcdDate instance
-
etcdb.
DateFromTicks
(ticks)[source]¶ This function constructs an object holding a time value from the given ticks value (number of seconds since the epoch; see the documentation of the standard Python time module for details).
Parameters: ticks – Seconds since Epoch Returns: EtcdDate
-
etcdb.
ETCDTABLELOCK
¶ alias of
etcdb.EtcdTableLock
-
etcdb.
Time
(hour, minute, second)[source]¶ This function constructs an object holding a time value.
Parameters: - hour – Hour, e.g. 15
- minute – Minute, e.g. 53
- second – Second, e.g. 16
Returns: EtcdTime instance
-
etcdb.
TimeFromTicks
(ticks)[source]¶ This function constructs an object holding a time value from the given ticks value (number of seconds since the epoch; see the documentation of the standard Python time module for details).
Parameters: ticks – Seconds since Epoch Returns: EtcdTime
-
etcdb.
Timestamp
(year, month, day, hour, minute, second)[source]¶ This function constructs an object holding a time stamp value.
Parameters: - year – See Date() and Time() arguments
- month –
- day –
- hour –
- minute –
- second –
Returns: EtcdTimestamp instance
-
etcdb.
TimestampFromTicks
(ticks)[source]¶ This function constructs an object holding a time stamp value from the given ticks value
(number of seconds since the epoch; see the documentation of the standard Python time module for details).
param ticks: Seconds since Epoch return: EtcTimestamp
-
etcdb.
apilevel
= '1.0'¶ supported DB API level.
-
etcdb.
paramstyle
= 'qmark'¶ the type of parameter marker formatting. Question mark style, e.g. …WHERE name=?.
-
etcdb.
threadsafety
= 3¶ the level of thread safety. Threads may share the module, connections and cursors.