operations – Everything RPC

Base classes

class ncclient.operations.RPC(session[, async=False, timeout=None, raise_mode="none"])

Base class for all operations, directly corresponding to rpc requests. Handles making the request, and taking delivery of the reply.

Subclasses can specify their dependencies on capabilities. List of URI’s or abbreviated names, e.g. ‘:writable-running’. These are verified at the time of instantiation. If the capability is not available, a MissingCapabilityError is raised.
Subclasses can specify a different reply class, but it should be a subclass of RPCReply.
Subclasses can use this method to verify that a capability is available with the NETCONF server, before making a request that requires it. A MissingCapabilityError will be raised if the capability is not available.

Implementations of request() call this method to send the request and process the reply.

In synchronous mode, blocks until the reply is received and returns RPCReply. Depending on the raise_mode a rpc-error element in the reply may lead to an RPCError exception.

In asynchronous mode, returns immediately, returning self. The event attribute will be set when the reply has been received (see reply) or an error occured (see error).

Parameter:op – operation to be requested
Return type:RPCReply (sync) or RPC (async)
request(*args, **kwds)
Subclasses must implement this method. Typically only the request needs to be built as an Element and everything else can be handed off to _request().
Event that is set when reply has been received or when an error preventing delivery of the reply occurs.

Exception type if an error occured or None.


This represents an error which prevented a reply from being received. An rpc-error does not fall in that category – see RPCReply for that.

RPCReply element if reply has been received or None

Depending on this exception raising mode, an rpc-error in the reply may be raised as RPCError exceptions. Valid values:

  • "all" – any kind of rpc-error (error or warning)
  • "errors" – when the error-type element says it is an error
  • "none" – neither
Specifies whether this RPC will be / was requested asynchronously. By default RPC’s are synchronous.

Timeout in seconds for synchronous waiting defining how long the RPC request will block on a reply before raising TimeoutExpiredError. By default there is no timeout, represented by None.

Irrelevant for asynchronous usage.

class ncclient.operations.RPCReply(raw)

Represents an rpc-reply. Only concerns itself with whether the operation was successful.


If the reply has not yet been parsed there is an implicit, one-time parsing overhead to accessing the attributes defined by this class and any subclasses.

rpc-reply element as returned.
Boolean value indicating if there were no errors.
Returns the first RPCError and None if there were no errors.
list of RPCError objects. Will be empty if there were no rpc-error elements in reply.
exception ncclient.operations.RPCError(raw)

Bases: ncclient.operations.errors.OperationError

Represents an rpc-error. It is a type of OperationError and can be raised like any other exception.

string representing text of error-type element.
string representing text of error-severity element.
string representing text of error-tag element.
string or None; representing text of error-path element.
string or None; representing text of error-message element.
string (XML) or None; representing error-info element.



The operation classes are currently undocumented. See documentation of Manager for methods that utilize the operation classes. The parameters accepted by request() for these classes are the same.

Replies with data

class ncclient.operations.GetReply(raw)

Bases: ncclient.operations.rpc.RPCReply

Adds attributes for the data element to RPCReply. This pertains to the Get and GetConfig operations.

Same as data_ele
data element as an Element
data element as an XML string


exception ncclient.operations.OperationError
Bases: ncclient.NCClientError
exception ncclient.operations.MissingCapabilityError
Bases: ncclient.NCClientError
exception ncclient.operations.TimeoutExpiredError
Bases: ncclient.NCClientError

Table Of Contents

Previous topic

transport – Transport / Session layer

Next topic

Extending ncclient

This Page