@@ -133,6 +133,14 @@ async def connect(
133133 metadata doesn't already have an "authorization" key.
134134 data_converter: Data converter to use for all data conversions
135135 to/from payloads.
136+ plugins: Set of plugins that are chained together to allow
137+ intercepting and modifying client creation and service connection.
138+ The earlier plugins wrap the later ones.
139+
140+ Any plugins that also implement
141+ :py:class:`temporalio.worker.Plugin` will be used as worker
142+ plugins too so they should not be given when creating a
143+ worker.
136144 interceptors: Set of interceptors that are chained together to allow
137145 intercepting of client calls. The earlier interceptors wrap the
138146 later ones.
@@ -7391,19 +7399,70 @@ async def _decode_user_metadata(
73917399
73927400
73937401class Plugin :
7402+ """Base class for client plugins that can intercept and modify client behavior.
7403+
7404+ Plugins allow customization of client creation and service connection processes
7405+ through a chain of responsibility pattern. Each plugin can modify the client
7406+ configuration or intercept service client connections.
7407+
7408+ If the plugin is also a temporalio.worker.Plugin, it will additionally be propagated as a worker plugin.
7409+ You should likley not also provide it to the worker as that will result in the plugin being applied twice.
7410+ """
7411+
73947412 def name (self ) -> str :
7413+ """Get the name of this plugin. Can be overridden if desired to provide a more appropriate name.
7414+
7415+ Returns:
7416+ The fully qualified name of the plugin class (module.classname).
7417+ """
73957418 return type (self ).__module__ + "." + type (self ).__qualname__
73967419
73977420 def init_client_plugin (self , next : Plugin ) -> Plugin :
7421+ """Initialize this plugin in the plugin chain.
7422+
7423+ This method sets up the chain of responsibility pattern by storing a reference
7424+ to the next plugin in the chain. It is called during client creation to build
7425+ the plugin chain.
7426+
7427+ Args:
7428+ next: The next plugin in the chain to delegate to.
7429+
7430+ Returns:
7431+ This plugin instance for method chaining.
7432+ """
73987433 self .next_client_plugin = next
73997434 return self
74007435
74017436 def on_create_client (self , config : ClientConfig ) -> ClientConfig :
7437+ """Hook called when creating a client to allow modification of configuration.
7438+
7439+ This method is called during client creation and allows plugins to modify
7440+ the client configuration before the client is fully initialized. Plugins
7441+ can add interceptors, modify connection parameters, or change other settings.
7442+
7443+ Args:
7444+ config: The client configuration dictionary to potentially modify.
7445+
7446+ Returns:
7447+ The modified client configuration.
7448+ """
74027449 return self .next_client_plugin .on_create_client (config )
74037450
74047451 async def connect_service_client (
74057452 self , config : temporalio .service .ConnectConfig
74067453 ) -> temporalio .service .ServiceClient :
7454+ """Hook called when connecting to the Temporal service.
7455+
7456+ This method is called during service client connection and allows plugins
7457+ to intercept or modify the connection process. Plugins can modify connection
7458+ parameters, add authentication, or provide custom connection logic.
7459+
7460+ Args:
7461+ config: The service connection configuration.
7462+
7463+ Returns:
7464+ The connected service client.
7465+ """
74077466 return await self .next_client_plugin .connect_service_client (config )
74087467
74097468
0 commit comments