pilosa package

Submodules

pilosa.client module

class pilosa.client.Client(cluster_or_uri=None, connect_timeout=30000, socket_timeout=300000, pool_size_per_route=10, pool_size_total=100, retry_count=3)[source]

Bases: object

Pilosa HTTP client

This client uses Pilosa’s http+protobuf API.

Usage:

import pilosa

# Create a Client instance
client = pilosa.Client()

# Create an Index instance
index = pilosa.Index("repository")

stargazer = index.frame("stargazer")
response = client.query(stargazer.bitmap(5))

# Act on the result
print(response.result)
create_frame(frame)[source]

Creates a frame on the server using the given Frame object.

Parameters:frame (pilosa.Frame) –
Raises:pilosa.FrameExistsError – if there already is a frame with the given name
create_index(index)[source]

Creates an index on the server using the given Index object.

Parameters:index (pilosa.Index) –
Raises:pilosa.IndexExistsError – if there already is a index with the given name
delete_frame(frame)[source]

Deletes the given frame on the server.

Parameters:frame (pilosa.Frame) –
Raises:pilosa.PilosaError – if the frame does not exist
delete_index(index)[source]

Deletes the given index on the server.

Parameters:index (pilosa.Index) –
Raises:pilosa.PilosaError – if the index does not exist
ensure_frame(frame)[source]

Creates a frame on the server if it does not exist.

Parameters:frame (pilosa.Frame) –
ensure_index(index)[source]

Creates an index on the server if it does not exist.

Parameters:index (pilosa.Index) –
import_frame(frame, bit_reader, batch_size=100000)[source]

Imports a frame using the given bit reader

Parameters:
  • frame
  • bit_reader
  • batch_size
query(query, columns=False)[source]

Runs the given query against the server with the given options.

Parameters:
  • query (pilosa.PqlQuery) – a PqlQuery object with a non-null index
  • columns (bool) – Enables returning column data from bitmap queries
Returns:

Pilosa response

Return type:

pilosa.Response

schema()[source]
status()[source]
sync_schema(schema)[source]
class pilosa.client.Cluster(*hosts)[source]

Contains hosts in a Pilosa cluster.

Parameters:hosts – URIs of hosts. Leaving out hosts creates the default cluster
add_host(uri)[source]

Makes a host available.

Parameters:uri (pilosa.URI) –
copy()[source]
get_host()[source]

Returns the next host in the cluster.

Returns:next host
Return type:pilosa.URI
remove_host(uri)[source]

Makes a host unavailable.

Parameters:uri (pilosa.URI) –
class pilosa.client.URI(scheme='http', host='localhost', port=10101)[source]

Represents a Pilosa URI

A Pilosa URI consists of three parts:

  • Scheme: Protocol of the URI. Default: http
  • Host: Hostname or IP URI. Default: localhost
  • Port: Port of the URI. Default 10101

All parts of the URI are optional. The following are equivalent:

  • http://localhost:10101
  • http://localhost
  • http://:10101
  • localhost:10101
  • localhost
  • :10101
Parameters:
  • scheme (str) – is the scheme of the Pilosa Server. Currently only http is supported
  • host (str) – is the hostname or IP address of the Pilosa server
  • port (int) – is the port of the Pilosa server
classmethod address(address)[source]

Creates a URI from an address.

Parameters:address (str) – of the form ${SCHEME}://${HOST}:{$PORT}
Returns:a Pilosa URI
Type:pilosa.URI

pilosa.exceptions module

exception pilosa.exceptions.PilosaError[source]

Bases: exceptions.Exception

exception pilosa.exceptions.ValidationError[source]

Bases: pilosa.exceptions.PilosaError

exception pilosa.exceptions.PilosaURIError[source]

Bases: pilosa.exceptions.PilosaError

exception pilosa.exceptions.IndexExistsError[source]

Bases: pilosa.exceptions.PilosaError

exception pilosa.exceptions.FrameExistsError[source]

Bases: pilosa.exceptions.PilosaError

pilosa.orm module

class pilosa.orm.TimeQuantum(value)[source]

Valid time quantum values for frames having support for that.

DAY = <pilosa.orm.TimeQuantum instance>
DAY_HOUR = <pilosa.orm.TimeQuantum instance>
HOUR = <pilosa.orm.TimeQuantum instance>
MONTH = <pilosa.orm.TimeQuantum instance>
MONTH_DAY = <pilosa.orm.TimeQuantum instance>
MONTH_DAY_HOUR = <pilosa.orm.TimeQuantum instance>
NONE = <pilosa.orm.TimeQuantum instance>
YEAR = <pilosa.orm.TimeQuantum instance>
YEAR_MONTH = <pilosa.orm.TimeQuantum instance>
YEAR_MONTH_DAY = <pilosa.orm.TimeQuantum instance>
YEAR_MONTH_DAY_HOUR = <pilosa.orm.TimeQuantum instance>
class pilosa.orm.CacheType(value)[source]
DEFAULT = <pilosa.orm.CacheType instance>
LRU = <pilosa.orm.CacheType instance>
RANKED = <pilosa.orm.CacheType instance>
class pilosa.orm.Schema[source]

Schema is a container for index objects

index(name, column_label='columnID', time_quantum=<pilosa.orm.TimeQuantum instance>)[source]

Returns an index object with the given name and options.

If the index didn’t exist in the schema, it is added to the schema.

Parameters:
  • name (str) – index name
  • column_label (str) – a valid column label
  • time_quantum (pilosa.TimeQuantum) – Sets the time quantum
Returns:

Index object

class pilosa.orm.Index(name, column_label='columnID', time_quantum=<pilosa.orm.TimeQuantum instance>)[source]

The purpose of the Index is to represent a data namespace.

You cannot perform cross-index queries. Column-level attributes are global to the Index.

Parameters:
  • name (str) – index name
  • column_label (str) – a valid column label
  • time_quantum (pilosa.TimeQuantum) – Sets the time quantum
batch_query(*queries)[source]

Creates a batch query.

Parameters:queries (pilosa.PQLQuery) – the queries in the batch
Returns:Pilosa batch query
Return type:pilosa.PQLBatchQuery
copy(frames=True)[source]
count(bitmap)[source]

Creates a Count query.

Count returns the number of set bits in the BITMAP_CALL passed in.

Parameters:bitmap (pilosa.PQLQuery) – the bitmap query
Returns:Pilosa query
Return type:pilosa.PQLQuery
difference(*bitmaps)[source]

Creates a Difference query.

Difference returns all of the bits from the first BITMAP_CALL argument passed to it, without the bits from each subsequent BITMAP_CALL.

Parameters:bitmaps (pilosa.PQLBitmapQuery) – 0 or more bitmap queries to differentiate
Returns:Pilosa bitmap query
Return type:pilosa.PQLBitmapQuery
Raises:PilosaError – if the number of bitmaps is less than 1
frame(name, row_label='rowID', time_quantum=<pilosa.orm.TimeQuantum instance>, inverse_enabled=False, cache_type=<pilosa.orm.CacheType instance>, cache_size=0)[source]

Creates a frame object with the specified name and defaults.

Parameters:
  • name (str) – frame name
  • row_label (str) – a valid row label
  • time_quantum (pilosa.TimeQuantum) – Sets the time quantum for the frame. If a Frame has a time quantum, then Views are generated for each of the defined time segments.
  • inverse_enabled (bool) –
  • cache_type (pilosa.CacheType) – CacheType.DEFAULT, CacheType.LRU or CacheType.RANKED
  • cache_size (int) – Values greater than 0 sets the cache size. Otherwise uses the default cache size
Returns:

Pilosa frame

Return type:

pilosa.Frame

intersect(*bitmaps)[source]

Creates an Intersect query.

Intersect performs a logical AND on the results of each BITMAP_CALL query passed to it.

Parameters:bitmaps (pilosa.PQLBitmapQuery) – 1 or more bitmap queries to intersect
Returns:Pilosa bitmap query
Return type:pilosa.PQLBitmapQuery
Raises:PilosaError – if the number of bitmaps is less than 1
raw_query(query)[source]

Creates a raw query.

Note that the query is not validated before sending to the server.

Parameters:query (str) –
Returns:Pilosa query
Return type:pilosa.PQLQuery
set_column_attrs(column_id, attrs)[source]

Creates a SetColumnAttrs query.

SetColumnAttrs associates arbitrary key/value pairs with a column in an index.

Following object types are accepted:

  • int
  • str
  • bool
  • float
Parameters:
  • column_id (int) –
  • attrs (dict) – column attributes
Returns:

Pilosa query

Return type:

pilosa.PQLQuery

union(*bitmaps)[source]

Creates a Union query.

Union performs a logical OR on the results of each BITMAP_CALL query passed to it.

Parameters:bitmaps (pilosa.PQLBitmapQuery) – 0 or more bitmap queries to union
Returns:Pilosa bitmap query
Return type:pilosa.PQLBitmapQuery
class pilosa.orm.PQLQuery(pql, index)[source]
serialize()[source]
class pilosa.orm.PQLBatchQuery(index)[source]
add(*queries)[source]
serialize()[source]

pilosa.response module

class pilosa.response.BitmapResult(bits=None, attributes=None)[source]

Represents a result from Bitmap, Union, Intersect, Difference and Range PQL calls.

classmethod from_internal(obj)[source]
class pilosa.response.CountResultItem(id, count)[source]

Represents a result from TopN call.

class pilosa.response.QueryResult(bitmap=None, count_items=None, count=0)[source]

Represent one of the results in the response.

classmethod from_internal(obj)[source]
class pilosa.response.ColumnItem(id, attributes)[source]

Contains data about a column.

Column data is returned from QueryResponse.getColumns() method. They are only returned if Client.query was called with columns=True.

class pilosa.response.QueryResponse(results=None, columns=None, error_message='')[source]

Bases: object

Represents the response from a Pilosa query.

column
result

pilosa.validator module

pilosa.validator.valid_index_name(index_name)[source]
pilosa.validator.validate_index_name(index_name)[source]
pilosa.validator.valid_frame_name(frame_name)[source]
pilosa.validator.validate_frame_name(frame_name)[source]
pilosa.validator.valid_label(label)[source]
pilosa.validator.validate_label(label)[source]

pilosa.version module

pilosa.version.get_version()[source]

Returns the version being used

Module contents