apache_beam.utils.urns module

For internal use only; no backwards-compatibility guarantees.

class apache_beam.utils.urns.RunnerApiFn[source]

Bases: future.types.newobject.newobject

Abstract base class that provides urn registration utilities.

A class that inherits from this class will get a registration-based from_runner_api and to_runner_api method that convert to and from beam_runner_api_pb2.SdkFunctionSpec.

Additionally, register_pickle_urn can be called from the body of a class to register serialization via pickling.

to_runner_api_parameter(unused_context)[source]

Returns the urn and payload for this Fn.

The returned urn(s) should be registered with register_urn.

classmethod register_urn(urn, parameter_type, fn=None)[source]

Registers a urn with a constructor.

For example, if ‘beam:fn:foo’ had parameter type FooPayload, one could write RunnerApiFn.register_urn(‘bean:fn:foo’, FooPayload, foo_from_proto) where foo_from_proto took as arguments a FooPayload and a PipelineContext. This function can also be used as a decorator rather than passing the callable in as the final parameter.

A corresponding to_runner_api_parameter method would be expected that returns the tuple (‘beam:fn:foo’, FooPayload)

classmethod register_pickle_urn(pickle_urn)[source]

Registers and implements the given urn via pickling.

to_runner_api(context)[source]

Returns an SdkFunctionSpec encoding this Fn.

Prefer overriding self.to_runner_api_parameter.

classmethod from_runner_api(fn_proto, context)[source]

Converts from an SdkFunctionSpec to a Fn object.

Prefer registering a urn with its parameter type and constructor.