client Package

client Package

connection Module

class crate.client.connection.Connection(servers=None, timeout=None, client=None)

Bases: object

close()

Close the connection now

commit()

Transactions are not supported, so commit is not implemented.

cursor()

Return a new Cursor Object using the connection.

get_blob_container(container_name)

Retrieve a BlobContainer for container_name

Parameters:container_name – the name of the BLOB container.
Returns:a :class:ContainerObject
crate.client.connection.connect(servers=None, timeout=None, client=None)

Create a :class:Connection object

Parameters:
  • servers – either a string in the form of ‘<hostname>:<port>’ or a list of servers in the form of [‘<hostname>:<port>’, ‘...’]
  • timeout – (optional) define the retry timeout for unreachable servers in seconds
  • client – (optional - for testing) client used to communicate with crate.
>>> connect(['host1:9200', 'host2:9200'])
<Connection <Client ['host1:9200', 'host2:9200']>>

crash Module

crate cli

can be used to query crate using SQL

class crate.client.crash.CrateCmd(*args)

Bases: cmd.Cmd

cols()
do_connect(server)

connect to one or more server with “connect servername:port”

do_delete(statement)

execute a SQL delete statement

E.g.:
“delete from locations where name = ‘Algol’
do_exit(*args)

exit the shell

do_insert(statement)

execute a SQL insert statement

E.g.:
“insert into locations (name) values (‘Algol’)
do_quit(*args)

exit the shell

do_select(statement)

execute a SQL select statement

E.g.:
“select name from locations where name = ‘Algol’”
execute(statement)
execute_query(statement)
pprint(rows)
prompt = 'cr> '
crate.client.crash.main()

cursor Module

class crate.client.cursor.Cursor(connection)

Bases: object

close()

Close the cursor now

description

This read-only attribute is a sequence of 7-item sequences.

execute(sql, parameters=None)

Prepare and execute a database operation (query or command).

executemany(sql, seq_of_parameters)

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()

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(count=None)

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()

Fetch the next row of a query result set, returning a single sequence, or None when no more data is available. Alias for next().

next()

Fetch the next row of a query result set, returning a single sequence, or None when no more data is available.

rowcount

This read-only attribute specifies the number of rows that the last .execute*() produced (for DQL statements like SELECT) or affected (for DML statements like UPDATE or INSERT).

setinputsizes(sizes)

Not supported method.

setoutputsize(size, column=None)

Not supported method.

exceptions Module

exception crate.client.exceptions.BlobException(table, digest)

Bases: exceptions.Exception

exception crate.client.exceptions.ConnectionError(msg=None)

Bases: crate.client.exceptions.OperationalError

exception crate.client.exceptions.DataError(msg=None)

Bases: crate.client.exceptions.DatabaseError

exception crate.client.exceptions.DatabaseError(msg=None)

Bases: crate.client.exceptions.Error

exception crate.client.exceptions.DigestNotFoundException(table, digest)

Bases: crate.client.exceptions.BlobException

exception crate.client.exceptions.Error(msg=None)

Bases: exceptions.StandardError

exception crate.client.exceptions.IntegrityError(msg=None)

Bases: crate.client.exceptions.DatabaseError

exception crate.client.exceptions.InterfaceError(msg=None)

Bases: crate.client.exceptions.Error

exception crate.client.exceptions.InternalError(msg=None)

Bases: crate.client.exceptions.DatabaseError

exception crate.client.exceptions.NotSupportedError(msg=None)

Bases: crate.client.exceptions.DatabaseError

exception crate.client.exceptions.OperationalError(msg=None)

Bases: crate.client.exceptions.DatabaseError

exception crate.client.exceptions.ProgrammingError(msg=None)

Bases: crate.client.exceptions.DatabaseError

exception crate.client.exceptions.Warning

Bases: exceptions.StandardError

http Module

class crate.client.http.Client(servers=None, timeout=None)

Bases: object

Crate connection client using crate’s HTTP API.

blob_del(table, digest)

Deletes the blob with given digest under the given table.

blob_exists(table, digest)

Returns true if the blob with the given digest exists under the given table.

blob_get(table, digest, chunk_size=131072)

Returns a file like object representing the contents of the blob with the given digest.

blob_put(table, digest, data)

Stores the contents of the file like @data object in a blob under the given table and digest.

default_server = '127.0.0.1:9200'

Default server to use if no servers are given on instantiation.

retry_interval = 30

Retry interval for failed servers in seconds.

sql(stmt, parameters=None)

Execute SQL stmt against the crate server.

sql_path = '_sql'

Crate URI path for issuing SQL statements.