pyhaystack.client.ops package

Submodules

pyhaystack.client.ops.entity module

Entity state machines. These are state machines that perform CRUD operations on entities.

class pyhaystack.client.ops.entity.EntityRetrieveOperation(session, single)

Bases: pyhaystack.util.state.HaystackOperation

Base class for retrieving entity instances.

Initialise a request for the named IDs.

Parameters:session – Haystack HTTP session object.
class pyhaystack.client.ops.entity.FindEntityOperation(session, filter_expr, limit, single)

Bases: pyhaystack.client.ops.entity.EntityRetrieveOperation

Operation for retrieving entity instances by filter. This operation peforms the following steps:

Issue a read instruction with the given filter:
    For each row returned in grid:
        If entity is not in cache:
            Create new Entity instances for each row returned.
        Else:
            Update existing Entity instance with new row data.
        Add the new entity instances to cache and store.
    Return the stored entities.
    # State: done

Initialise a request for the named IDs.

Parameters:
  • session – Haystack HTTP session object.
  • filter_expr – Filter expression.
  • limit – Maximum number of entities to fetch.
go()

Start the request, check cache for existing entities.

class pyhaystack.client.ops.entity.GetEntityOperation(session, entity_ids, refresh_all, single)

Bases: pyhaystack.client.ops.entity.EntityRetrieveOperation

Operation for retrieving entity instances by ID. This operation peforms the following steps:

If refresh_all is False:
# State: init
    For each entity_id in entity_ids:
        If entity_id exists in cache:
            Retrieve and store entity from cache.
            Add entity_id to list got_ids.
    For each entity_id in got_ids:
        Discard entity_id from entity_ids.
If entity_ids is not empty:
# State: read
    Perform a low-level read of the IDs.
    For each row returned in grid:
        If entity is not in cache:
            Create new Entity instances for each row returned.
        Else:
            Update existing Entity instance with new row data.
    Add the new entity instances to cache and store.
Return the stored entities.
# State: done

Initialise a request for the named IDs.

Parameters:
  • session – Haystack HTTP session object.
  • entity_ids – A list of IDs to request.
  • refresh_all – Refresh all entities, ignore existing content.
go()

Start the request, check cache for existing entities.

pyhaystack.client.ops.grid module

Low-level grid state machines. These are state machines that perform GET or POST requests involving Haystack ZINC grids.

class pyhaystack.client.ops.grid.BaseAuthOperation(session, uri, retries=2, cache=False)

Bases: pyhaystack.util.state.HaystackOperation

A base class authentication operations.

Initialise a request for the authenticating with the given URI and arguments.

It also contains the state machine for reconnection if needed.

Parameters:
  • session – Haystack HTTP session object.
  • uri – Possibly partial URI relative to the server base address to perform a query. No arguments shall be given here.
  • retries – Number of retries permitted in case of failure.
  • cache – Whether or not to cache this result. If True, the result is cached by the session object.
go()

Start the request.

class pyhaystack.client.ops.grid.BaseGridOperation(session, uri, args=None, expect_format='text/zinc', multi_grid=False, raw_response=False, retries=2, cache=False, cache_key=None, accept_status=None, headers=None, exclude_cookies=None)

Bases: pyhaystack.client.ops.grid.BaseAuthOperation

A base class for GET and POST operations involving grids.

Initialise a request for the grid with the given URI and arguments.

Parameters:
  • session – Haystack HTTP session object.
  • uri – Possibly partial URI relative to the server base address to perform a query. No arguments shall be given here.
  • expect_format – Request that the grid be sent in the given format.
  • args – Dictionary of key-value pairs to be given as arguments.
  • multi_grid – Boolean indicating if we are to expect multiple grids or not. If True, then the operation will _always_ return a list, otherwise, it will _always_ return a single grid.
  • raw_response – Boolean indicating if we should try to parse the result. If True, then we should just pass back the raw HTTPResponse object.
  • retries – Number of retries permitted in case of failure.
  • cache – Whether or not to cache this result. If True, the result is cached by the session object.
  • cache_key – Name of the key to use when the object is cached.
  • accept_status – What status codes to accept, in addition to the usual ones?
  • exclude_cookies – If True, exclude all default cookies and use only the cookies given. Otherwise, this is an iterable of cookie names to be excluded.
class pyhaystack.client.ops.grid.GetGridOperation(session, uri, args=None, multi_grid=False, **kwargs)

Bases: pyhaystack.client.ops.grid.BaseGridOperation

A state machine that performs a GET operation then reads back a ZINC grid.

Initialise a GET request for the grid with the given URI and arguments.

Parameters:
  • session – Haystack HTTP session object.
  • uri – Possibly partial URI relative to the server base address to perform a query. No arguments shall be given here.
  • args – Dictionary of key-value pairs to be given as arguments.
  • multi_grid – Boolean indicating if we are to expect multiple grids or not. If true, then the operation will _always_ return a list, otherwise, it will _always_ return a single grid.
class pyhaystack.client.ops.grid.PostGridOperation(session, uri, grid, args=None, post_format='text/zinc', **kwargs)

Bases: pyhaystack.client.ops.grid.BaseGridOperation

A state machine that performs a POST operation with a ZINC grid then may read back a ZINC grid.

Initialise a POST request for the grid with the given grid, URI and arguments.

Parameters:
  • session – Haystack HTTP session object.
  • uri – Possibly partial URI relative to the server base address to perform a query. No arguments shall be given here.
  • grid – Grid (or grids) to be posted to the server.
  • post_format – What format to post grids in?
  • args – Dictionary of key-value pairs to be given as arguments.
pyhaystack.client.ops.grid.dict_to_grid(d)

pyhaystack.client.ops.his module

High-level history functions. These wrap the basic his_read function to allow some alternate representations of the historical data.

class pyhaystack.client.ops.his.HisReadFrameOperation(session, columns, rng, tz, frame_format)

Bases: pyhaystack.util.state.HaystackOperation

Read the series data from several ‘point’ entities and present them in a concise format.

Read the series data and return it.

Parameters:
  • session – Haystack HTTP session object.
  • columns – IDs of historical point objects to read.
  • rng – Range to read from ‘point’
  • tz – Timezone to translate timezones to. May be None.
  • frame_format – What format to present the frame in.
FORMAT_DICT = 'dict'
FORMAT_FRAME = 'frame'
FORMAT_LIST = 'list'
go()

Start processing the operation. This is called by the caller (so after all __init__ functions have executed) in order to begin the asynchronous operation.

class pyhaystack.client.ops.his.HisReadSeriesOperation(session, point, rng, tz, series_format)

Bases: pyhaystack.util.state.HaystackOperation

Read the series data from a ‘point’ entity and present it in a concise format.

Read the series data and return it.

Parameters:
  • session – Haystack HTTP session object.
  • point – ID of historical ‘point’ object to read.
  • rng – Range to read from ‘point’
  • tz – Timezone to translate timezones to. May be None.
  • series_format – What format to present the series in.
FORMAT_DICT = 'dict'
FORMAT_LIST = 'list'
FORMAT_SERIES = 'series'
go()

Start processing the operation. This is called by the caller (so after all __init__ functions have executed) in order to begin the asynchronous operation.

class pyhaystack.client.ops.his.HisWriteFrameOperation(session, columns, frame, tz)

Bases: pyhaystack.util.state.HaystackOperation

Write the series data to several ‘point’ entities.

Write the series data.

Parameters:
  • session – Haystack HTTP session object.
  • columns – IDs of historical point objects to read.
  • frame – Range to read from ‘point’
  • tz – Timezone to translate timezones to.
go()

Start processing the operation. This is called by the caller (so after all __init__ functions have executed) in order to begin the asynchronous operation.

class pyhaystack.client.ops.his.HisWriteSeriesOperation(session, point, series, tz)

Bases: pyhaystack.util.state.HaystackOperation

Write the series data to a ‘point’ entity.

Write the series data to the point.

Parameters:
  • session – Haystack HTTP session object.
  • point – ID of historical ‘point’ object to write.
  • series – Series data to be written to the point.
  • tz – If not None, a datetime.tzinfo instance for this write.
go()

Start processing the operation. This is called by the caller (so after all __init__ functions have executed) in order to begin the asynchronous operation.

class pyhaystack.client.ops.his.MetaDataFrame(*args, **kw)

Bases: pandas.core.frame.DataFrame

Custom Pandas Dataframe with meta data Made from MetaSeries

add_meta(key, value)
meta = {}
class pyhaystack.client.ops.his.MetaSeries(data=None, index=None, dtype=None, name=None, copy=False, fastpath=False)

Bases: pandas.core.series.Series

Custom Pandas Serie with meta data

add_meta(key, value)
meta = {}

Module contents