Connector | PyF, flow-based python programming Connector

Connector

pyf.elevator.Connector

class pyf.elevator.Connector(address, port=80, protocol='http', encoding='UTF-8', path='')

The base pyf.services client class.

If you connect to several servers, instanciate one connector per server.

Example:

>>> connector = Connector('localhost', port=8080)
>>> connector.login('manager', 'managepass')
call(module, action=None, extension=None, params=None, **kwargs)

Calls an action on the server and returns the raw http result.

Parameters:
  • module (str) – The module that has to be called (Example: “tubes”)
  • action (None, str or list) – The action that has to be called (can be a list)
  • extension (string or None) – The extension of the file (Example: ”.json”)
  • params (dict or None) – that params that have to be passed to the controller (if no params is passed, uses **kwargs if set instead)
Return type:

response file-like object

call_json(module, action=None, params=None, **kwargs)

Same than pyf.elevator.Connector.call() but parses the response as json.

Parameters:
  • module (str) – The module that has to be called (Example: “tubes”)
  • action (None, str or list) – The action that has to be called (can be a list)
  • params (dict or None) – that params that have to be passed to the controller (if no params is passed, uses **kwargs if set instead)
Return type:

dict, list or None

login(username, password)

Logs you in.

If login fails, it raises a LoginError.

logout()

Logs you out. If logout fails, it raises a LogoutError

Data objects

pyf.elevator.Tube

class pyf.elevator.Tube(client, id=None, data=None)

Client-side equivalent of pyf.services.model.Tube.

Parameters:
  • client (instance of pyf.elevator.Connector) – The connector on which the object is used
  • id (None or int) – The id of the object
  • data (dict or None) – Data already fetched for the object. If it is not passed and the id is not None, the object will be fetched on the server
classmethod by_name(client, name)

Returns a tube by its name.

Parameters:
  • client (instance of pyf.elevator.Connector) – The connector on which the object is used
  • name (str) – The name of the tube to search

Example:

>>> data_tube = Tube.by_name(connector, "tube_xyz")
classmethod create(client, data)

Creates a new item of this type with the data provided.

Parameters:
dispatchs

Returns the pyf.elevator.Dispatch instances associated with this tube.

launch(variant=None, packet_flow=None, options=None)

Launch the tube with the given (optional) variant, packet flow and options.

Parameters:
  • variant (str or None) – The variant with which to launch the processing
  • packet_flow (None, an iterator over pyf.transport.Packet objects or a file-like object of serialized packets (using pyf.transport.encode_packet_flow()).) – An optional packet flow to be passed to the tube. If the tube needs a source, it will be given this data directly, without needing a dispatch.
  • options (dict or None) – The parameters to be passed to the processing
Return type:

The pyf.elevator.Event instance of the launched event.

classmethod list(client, **kwargs)

Gets a list of all items of this type on the server.

Parameters:
parameters

Returns the available parameters for the tube.

Return type:dict or None
update()

Updates the data of the object

pyf.elevator.TubeLayer

class pyf.elevator.TubeLayer(client, id=None, data=None)

Client-side equivalent of pyf.services.model.TubeLayer.

Parameters:
  • client (instance of pyf.elevator.Connector) – The connector on which the object is used
  • id (None or int) – The id of the object
  • data (dict or None) – Data already fetched for the object. If it is not passed and the id is not None, the object will be fetched on the server
classmethod create(client, data)

Creates a new item of this type with the data provided.

Parameters:
classmethod list(client, **kwargs)

Gets a list of all items of this type on the server.

Parameters:
update()

Updates the data of the object

pyf.elevator.Descriptor

class pyf.elevator.Descriptor(client, id=None, data=None)
classmethod create(client, data)

Creates a new item of this type with the data provided.

Parameters:
classmethod list(client, **kwargs)

Gets a list of all items of this type on the server.

Parameters:
update()

Updates the data of the object

pyf.elevator.Dispatch

class pyf.elevator.Dispatch(client, id=None, data=None)

Client-side equivalent of pyf.services.model.Dispatch.

Parameters:
  • client (instance of pyf.elevator.Connector) – The connector on which the object is used
  • id (None or int) – The id of the object
  • data (dict or None) – Data already fetched for the object. If it is not passed and the id is not None, the object will be fetched on the server
classmethod by_name(client, name)

Returns a dispatch by its name.

Parameters:
  • client (instance of pyf.elevator.Connector) – The connector on which the object is used
  • name (str) – The name of the dispatch to search

Example:

>>> data_dispatch = Dispatch.by_name(connector, "dispatch_xyz")
classmethod create(client, data)

Creates a new item of this type with the data provided.

Parameters:
descriptor

Returns the pyf.elevator.Descriptor instance associated with this dispatch.

classmethod list(client, **kwargs)

Gets a list of all items of this type on the server.

Parameters:
tube

Returns the pyf.elevator.Tube instance associated with this dispatch.

update()

Updates the data of the object

upload(document, encoding=None, variant=None, options=None)

Uploads a file to the dispatch.

Parameters:
  • document (file-like or str) – The file to be opened. Can be either a file-like or a path.
  • encoding (str or None) – The encoding of the document
  • variant (str or None) – The variant with which to launch the processing
  • options (dict or None) – The parameters to be passed to the processing
Return type:

The pyf.elevator.Event instance of the launched event.

pyf.elevator.Event

class pyf.elevator.Event(client, id=None, data=None)

Client-side equivalent of pyf.services.model.EventTrack. This is the object returned when you launch a processing.

Example:

>>> my_event.update()
>>> my_event.progression
10.00
>>> my_event.status
'processing'
>>> my_event.update()
>>> my_event.progression
100.00
>>> my_event.status
'success'
>>> for filename, fileobj in my_event.get_output_files():
...     print filename
myfile.csv
myfile.pdf
Parameters:
  • client (instance of pyf.elevator.Connector) – The connector on which the object is used
  • id (None or int) – The id of the object
  • data (dict or None) – Data already fetched for the object. If it is not passed and the id is not None, the object will be fetched on the server
classmethod create(client, data)

Creates a new item of this type with the data provided.

Parameters:
dispatch

Returns the pyf.elevator.Dispatch instances associated with this event.

get_output_files()

Returns an iterator of tuples containing filenames and file-like objects

classmethod list(client, **kwargs)

Gets a list of all items of this type on the server.

Parameters:
progression

Returns the progression as a decimal.

Hint

Don’t forget to update() the object before reading the progression

tube

Returns the pyf.elevator.Tube instances associated with this event.

update()

Updates the data of the object

pyf.elevator.TubeStorage

class pyf.elevator.TubeStorage(client, id=None, data=None)
classmethod create(client, data)

Creates a new item of this type with the data provided.

Parameters:
classmethod list(client, **kwargs)

Gets a list of all items of this type on the server.

Parameters:
update()

Updates the data of the object