API¶
This page contains a list of all functions and classes in MonetDBe-Python project (monetdbe).
Connection¶
This module contains the monetdbe connection class.
- class monetdbe.connection.Connection(database: Optional[Union[str, pathlib.Path]] = None, uri: bool = False, timeout: int = 0, detect_types: int = 0, check_same_thread: bool = True, autocommit: bool = False, nr_threads: int = 0, memorylimit: int = 0, querytimeout: int = 0, logging: Optional[pathlib.Path] = None, username: Optional[str] = None, password: Optional[str] = None, host: Optional[str] = None, port: Optional[int] = None, usock: Optional[pathlib.Path] = None)¶
Bases:
object
- exception DataError¶
Bases:
monetdbe.exceptions.DatabaseError
Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range, etc. It must be a subclass of DatabaseError.
- exception DatabaseError¶
Bases:
monetdbe.exceptions.Error
Exception raised for errors that are related to the database. It must be a subclass of Error.
- exception Error¶
Bases:
Exception
Exception that is the base class of all other error exceptions. You can use this to catch all errors with one single ‘except’ statement. Warnings are not considered errors and thus should not use this class as base. It must be a subclass of the Python StandardError (defined in the module exceptions).
- exception IntegrityError¶
Bases:
monetdbe.exceptions.DatabaseError
Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails. It must be a subclass of DatabaseError.
- exception InterfaceError¶
Bases:
monetdbe.exceptions.Error
Exception raised for errors that are related to the database interface rather than the database itself. It must be a subclass of Error.
- exception InternalError¶
Bases:
monetdbe.exceptions.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. It must be a subclass of DatabaseError.
- exception NotSupportedError¶
Bases:
monetdbe.exceptions.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. It must be a subclass of DatabaseError.
- exception OperationalError¶
Bases:
monetdbe.exceptions.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. It must be a subclass of DatabaseError.
- exception ProgrammingError¶
Bases:
monetdbe.exceptions.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. It must be a subclass of DatabaseError.
- exception Warning¶
Bases:
Exception
Exception raised for important warnings like data truncations while inserting, etc. It must be a subclass of the Python StandardError (defined in the module exceptions).
- append(table: str, data: Mapping[str, numpy.ndarray], schema: str = 'sys') None ¶
- backup(*args, **kwargs)¶
- cleanup_result()¶
- cleanup_statement(statement: str) None ¶
- close(*args, **kwargs) None ¶
- create_aggregate(*args, **kwargs)¶
- create_collation(*args, **kwargs)¶
- create_function(*args, **kwargs)¶
- cursor(factory: Optional[Type[Cursor]] = None) Cursor ¶
Create a new cursor.
- Parameters
factory – An optional factory. If supplied, this must be a callable returning an instance of Cursor or its subclasses.
- Returns
a new cursor.
- execute(query: str, args: Optional[Union[Sequence[Any], Dict[str, Any]]] = None, cursor: Optional[Type[Cursor]] = None, paramstyle: str = 'qmark') Cursor ¶
Execute a SQL query
This is a nonstandard and SQLite compatible shortcut that creates a cursor object by calling the cursor() method, calls the cursor’s execute() method with the parameters given, and returns the cursor.
- Parameters
query – The SQL query to execute
args – The optional SQL query arguments
cursor – An optional Cursor object
paramstyle – The style of the args, can be qmark, numeric, format or pyformat
- Returns
A new cursor.
- executemany(query: str, args_seq: Union[Iterator, Iterable[Optional[Union[Sequence[Any], Dict[str, Any]]]]], cursor: Optional[Type[Cursor]] = None) Cursor ¶
Prepare a database query and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters.
This is a nonstandard and SQLite compatible shortcut that creates a cursor object by calling the cursor() method, calls the cursor’s execute() method with the parameters given, and returns the cursor.
- Parameters
query – The SQL query to execute
args_seq – The optional SQL query arguments
cursor – A Cursor class
- Returns
A new cursor instance of the supplied cursor class
- executescript(sql_script: str)¶
- get_description()¶
- get_port() Optional[int] ¶
- property in_transaction¶
- iterdump(*args, **kwargs)¶
- prepare(operation: str)¶
- query(query: str, make_result: bool = False) Tuple[Optional[Any], int] ¶
Execute a query directly on the connection.
You probably don’t want to use this. usually you use a cursor to execute queries.
- read_csv(table, *args, **kwargs)¶
- rollback(*args, **kwargs)¶
Rolls back the current transaction.
- set_authorizer(*args, **kwargs)¶
- set_autocommit(value: bool) None ¶
Set the connection to auto-commit mode.
- Parameters
value – a boolean value
- set_progress_handler(*args, **kwargs)¶
- set_trace_callback(*args, **kwargs)¶
- write_csv(table, *args, **kwargs)¶
- class monetdbe.connection.Description(name, type_code, display_size, internal_size, precision, scale, null_ok)¶
Bases:
tuple
- property display_size¶
Alias for field number 2
- property internal_size¶
Alias for field number 3
- property name¶
Alias for field number 0
- property null_ok¶
Alias for field number 6
- property precision¶
Alias for field number 4
- property scale¶
Alias for field number 5
- property type_code¶
Alias for field number 1
Cursor¶
- class monetdbe.cursors.Cursor(con: monetdbe.connection.Connection)¶
Bases:
object
- close() None ¶
Shut down the connection.
- commit() monetdbe.cursors.Cursor ¶
Commit the current pending transaction.
- Returns
the current cursor
- create(table, values, schema=None)¶
Creates a table from a set of values or a pandas DataFrame.
- execute(operation: str, parameters: Optional[Union[Sequence[Any], Dict[str, Any]]] = None, paramstyle: str = 'qmark') monetdbe.cursors.Cursor ¶
- executemany(operation: str, seq_of_parameters: Union[Iterator, Iterable[Iterable]]) monetdbe.cursors.Cursor ¶
Prepare a database operation (query or command) and then execute it against all parameter sequences or mappings found in the sequence seq_of_parameters.
- Parameters
operation – the SQL query to execute
seq_of_parameters – An optional iterator or iterable containing an iterable of arguments
- executescript(sql_script: str) None ¶
This is a nonstandard convenience and SQLite compatibility method for executing multiple SQL statements at once. It issues a COMMIT statement first, then executes the SQL script it gets as a parameter.
- Parameters
sql_script – A string containing one or more SQL statements, split by ;
- Raises
Error – If the previous call to .execute*() did not produce any result set or no call was issued yet.
- fetchall() List[Union[Row, Sequence]] ¶
Fetch all (remaining) rows of a query result, returning them as a list of tuples).
- Returns
all (remaining) rows of a query result as a list of tuples
- Raises
Error – If the previous call to .execute*() did not produce any result set or no call was issued yet.
- fetchdf() pandas.core.frame.DataFrame ¶
Fetch all results and return a Pandas DataFrame.
like .fetchall(), but returns a Pandas DataFrame.
- fetchmany(size=None)¶
Fetch the next set of rows of a query result, returning a list of tuples). An empty sequence is returned when no more rows are available.
- Parameters
size – The number of rows to fetch. Fewer rows may be returned.
Returns: A number of rows from a query result as a list of tuples
- Raises
Error – If the previous call to .execute*() did not produce any result set or no call was issued yet.
- fetchnumpy() Mapping[str, numpy.ndarray] ¶
Fetch all results and return a numpy array.
like .fetchall(), but returns a numpy array.
- fetchone() Optional[Union[Row, Sequence]] ¶
Fetch the next row of a query result set, returning a single tuple, or None when no more data is available.
- Returns
One row from a result set.
- Raises
Error – If the previous call to .execute*() did not produce any result set or no call was issued yet.
- insert(table: str, values: Union[pandas.core.frame.DataFrame, Mapping[str, numpy.ndarray]], schema: str = 'sys')¶
Inserts a set of values into the specified table.
- Parameters
table – The table to insert into
values – The values. must be either a pandas DataFrame or a dictionary of values.
schema – The SQL schema to use. If no schema is specified, the “sys” schema is used.
- lastrowid = 0¶
- read_csv(table, *args, **kwargs)¶
- scroll(count: int, mode: str = 'relative')¶
Scroll the cursor in the result set to a new position according to mode.
We dont support scrolling, since the full result is available.
- setinputsizes(*args, **kwargs) None ¶
This method would normally be used before the .execute*() method is invoked to reserve memory.
MonetDBe-Python does not require this, so calling this function has no effect.
- setoutputsize(*args, **kwargs) None ¶
This method would normally set a column buffer size for fetching of large columns.
MonetDBe-Python does not require this, so calling this function has no effect.
- transaction()¶
Start a new transaction
- Returns
the current cursor
- write_csv(table, *args, **kwargs)¶
Row¶
- class monetdbe.row.Row(cur: Cursor, row: Union[tuple, Generator[Optional[Any], Any, None]])¶
Bases:
object
A Row is a non-standard SQLite compatible data container. It tries to mimic a tuple in most of its features.
It supports mapping access by column name and index, iteration, representation, equality testing and len().
If two Row objects have exactly the same columns and their members are equal, they compare equal.
- keys() Tuple[Any, ...] ¶