blpapi.Service

class blpapi.Service(handle, sessions)

Defines a service which provides access to API data.

A Service object is obtained from a Session and contains the Operations (each of which contains its own schema) and the schema for Events which this Service may produce. A Service object is also used to create Request objects used with a Session to issue requests.

Provider services are created to generate API data and must be registered before use.

The Service object is a handle to the underlying data which is owned by the Session. Once a Service has been succesfully opened in a Session it remains accessible until the Session is terminated.

authorizationServiceName()

Get the authorization service name.

Return type

str

Returns

The name of the Service which must be used in order to authorize access to restricted operations on this Service. If no authorization is required to access operations on this service an empty string is returned.

Authorization services never require authorization to use.

createAdminEvent()
Return type

Event

Returns

An ADMIN Event suitable for publishing to this Service

Use an EventFormatter to add Messages to the Event and set fields.

DEPRECATED Use Service.createPublishEvent().

createAuthorizationRequest(authorizationOperation=None)

Create an empty Request object for authorizationOperation.

Parameters

authorizationOperation (Optional[str]) – A valid operation on this service

Return type

Request

Returns

An empty request for the specified authorizationOperation.

Raises

Exception – If authorizationOperation does not identify a valid operation in the Service

An application must populate the Request before issuing it using Session.sendAuthorizationRequest().

createPublishEvent()
Return type

Event

Returns

Event suitable for publishing to this Service

Use an EventFormatter to add Messages to the Event and set fields.

createRequest(operation)

Create an empty Request object for the specified operation.

Parameters

operation (str) – A valid operation on this service

Return type

Request

Returns

An empty request for the specified operation.

Raises

Exception – If operation does not identify a valid operation in the Service

An application must populate the Request before issuing it using Session.sendRequest().

createResponseEvent(correlationId)

Create a RESPONSE Event to answer the request.

Parameters

correlationId – Correlation id to associate with the created event

Returns

The created response event.

Use an EventFormatter to add Messages to the Event and set fields.

description()
Returns

Human-readable description of this service.

Return type

str

destroy()

Destroy the handle using stored dtor

Return type

None

eventDefinitions()
Return type

Iterator[SchemaElementDefinition]

Returns

An iterator over unsolicited events defined by this Service.

getEventDefinition(nameOrIndex)

Get the definition of a specified event.

Parameters

nameOrIndex (Union[Name, int]) – Name or index of the event

Return type

SchemaElementDefinition

Returns

Object describing the element identified by the specified nameOrIndex.

Raises

Note

Please use Name over str where possible for nameOrIndex. Name objects should be initialized once and then reused in order to minimize lookup cost.

getOperation(nameOrIndex)
Parameters

nameOrIndex (Union[Name, int]) – Name or index of the operation

Return type

Operation

Returns

The specified operation.

Raises

Exception – If nameOrIndex is a string or a Name and hasOperation(nameOrIndex) != True, or if nameOrIndex is an integer and nameOrIndex >= numOperations().

Note

Please use Name over str where possible for nameOrIndex. Name objects should be initialized once and then reused in order to minimize lookup cost.

hasEventDefinition(name)
Parameters

name – Event identifier

Returns

True if the specified name identifies a valid event in this Service, False otherwise.

Raises

Exception – If name is neither a Name nor a string.

Note

Please use Name over str where possible for name. Name objects should be initialized once and then reused in order to minimize lookup cost.

hasOperation(name)
Returns

True if the specified name is a valid Operation in this Service.

name()
Return type

str

Returns

Name of this service.

numEventDefinitions()
Return type

int

Returns

The number of unsolicited events defined by this Service.

numOperations()
Return type

int

Returns

The number of Operations defined by this Service.

operations()
Return type

Iterator[Operation]

Returns

Iterator over Operations defined by this Service

toString(level=0, spacesPerLevel=4)

Convert this Service schema to a string.

Parameters
  • level (int) – Indentation level

  • spacesPerLevel (int) – Number of spaces per indentation level for this and all nested objects

Return type

str

Returns

This object formatted as a string

If level is negative, suppress indentation of the first line. If spacesPerLevel is negative, format the entire output on one line, suppressing all but the initial indentation (as governed by level).