@@ -564,6 +564,57 @@ def delete_source(
564564 )
565565
566566
567+ def patch_source (
568+ source_id : str ,
569+ * ,
570+ api_root : str ,
571+ client_id : SecretString ,
572+ client_secret : SecretString ,
573+ name : str | None = None ,
574+ config : models .SourceConfiguration | dict [str , Any ] | None = None ,
575+ ) -> models .SourceResponse :
576+ """Update/patch a source configuration.
577+
578+ This is a destructive operation that can break existing connections if the
579+ configuration is changed incorrectly.
580+
581+ Args:
582+ source_id: The ID of the source to update
583+ api_root: The API root URL
584+ client_id: Client ID for authentication
585+ client_secret: Client secret for authentication
586+ name: Optional new name for the source
587+ config: Optional new configuration for the source
588+
589+ Returns:
590+ Updated SourceResponse object
591+ """
592+ airbyte_instance = get_airbyte_server_instance (
593+ client_id = client_id ,
594+ client_secret = client_secret ,
595+ api_root = api_root ,
596+ )
597+ response = airbyte_instance .sources .patch_source (
598+ api .PatchSourceRequest (
599+ source_id = source_id ,
600+ source_patch_request = models .SourcePatchRequest (
601+ name = name ,
602+ configuration = config ,
603+ ),
604+ ),
605+ )
606+ if status_ok (response .status_code ) and response .source_response :
607+ return response .source_response
608+
609+ raise AirbyteError (
610+ message = "Could not update source." ,
611+ context = {
612+ "source_id" : source_id ,
613+ },
614+ response = response ,
615+ )
616+
617+
567618# Utility function
568619
569620
@@ -701,9 +752,80 @@ def delete_destination(
701752 )
702753
703754
755+ def patch_destination (
756+ destination_id : str ,
757+ * ,
758+ api_root : str ,
759+ client_id : SecretString ,
760+ client_secret : SecretString ,
761+ name : str | None = None ,
762+ config : DestinationConfiguration | dict [str , Any ] | None = None ,
763+ ) -> models .DestinationResponse :
764+ """Update/patch a destination configuration.
765+
766+ This is a destructive operation that can break existing connections if the
767+ configuration is changed incorrectly.
768+
769+ Args:
770+ destination_id: The ID of the destination to update
771+ api_root: The API root URL
772+ client_id: Client ID for authentication
773+ client_secret: Client secret for authentication
774+ name: Optional new name for the destination
775+ config: Optional new configuration for the destination
776+
777+ Returns:
778+ Updated DestinationResponse object
779+ """
780+ airbyte_instance = get_airbyte_server_instance (
781+ client_id = client_id ,
782+ client_secret = client_secret ,
783+ api_root = api_root ,
784+ )
785+ response = airbyte_instance .destinations .patch_destination (
786+ api .PatchDestinationRequest (
787+ destination_id = destination_id ,
788+ destination_patch_request = models .DestinationPatchRequest (
789+ name = name ,
790+ configuration = config ,
791+ ),
792+ ),
793+ )
794+ if status_ok (response .status_code ) and response .destination_response :
795+ return response .destination_response
796+
797+ raise AirbyteError (
798+ message = "Could not update destination." ,
799+ context = {
800+ "destination_id" : destination_id ,
801+ },
802+ response = response ,
803+ )
804+
805+
704806# Create and delete connections
705807
706808
809+ def build_stream_configurations (
810+ stream_names : list [str ],
811+ ) -> models .StreamConfigurations :
812+ """Build a StreamConfigurations object from a list of stream names.
813+
814+ This helper creates the proper API model structure for stream configurations.
815+ Used by both connection creation and updates.
816+
817+ Args:
818+ stream_names: List of stream names to include in the configuration
819+
820+ Returns:
821+ StreamConfigurations object ready for API submission
822+ """
823+ stream_configurations = [
824+ models .StreamConfiguration (name = stream_name ) for stream_name in stream_names
825+ ]
826+ return models .StreamConfigurations (streams = stream_configurations )
827+
828+
707829def create_connection ( # noqa: PLR0913 # Too many arguments
708830 name : str ,
709831 * ,
@@ -722,15 +844,7 @@ def create_connection( # noqa: PLR0913 # Too many arguments
722844 client_secret = client_secret ,
723845 api_root = api_root ,
724846 )
725- stream_configurations : list [models .StreamConfiguration ] = []
726- if selected_stream_names :
727- for stream_name in selected_stream_names :
728- stream_configuration = models .StreamConfiguration (
729- name = stream_name ,
730- )
731- stream_configurations .append (stream_configuration )
732-
733- stream_configurations_obj = models .StreamConfigurations (stream_configurations )
847+ stream_configurations_obj = build_stream_configurations (selected_stream_names )
734848 response = airbyte_instance .connections .create_connection (
735849 models .ConnectionCreateRequest (
736850 name = name ,
@@ -815,6 +929,66 @@ def delete_connection(
815929 )
816930
817931
932+ def patch_connection ( # noqa: PLR0913 # Too many arguments
933+ connection_id : str ,
934+ * ,
935+ api_root : str ,
936+ client_id : SecretString ,
937+ client_secret : SecretString ,
938+ name : str | None = None ,
939+ configurations : models .StreamConfigurationsInput | None = None ,
940+ schedule : models .AirbyteAPIConnectionSchedule | None = None ,
941+ prefix : str | None = None ,
942+ status : models .ConnectionStatusEnum | None = None ,
943+ ) -> models .ConnectionResponse :
944+ """Update/patch a connection configuration.
945+
946+ This is a destructive operation that can break existing connections if the
947+ configuration is changed incorrectly.
948+
949+ Args:
950+ connection_id: The ID of the connection to update
951+ api_root: The API root URL
952+ client_id: Client ID for authentication
953+ client_secret: Client secret for authentication
954+ name: Optional new name for the connection
955+ configurations: Optional new stream configurations
956+ schedule: Optional new sync schedule
957+ prefix: Optional new table prefix
958+ status: Optional new connection status
959+
960+ Returns:
961+ Updated ConnectionResponse object
962+ """
963+ airbyte_instance = get_airbyte_server_instance (
964+ client_id = client_id ,
965+ client_secret = client_secret ,
966+ api_root = api_root ,
967+ )
968+ response = airbyte_instance .connections .patch_connection (
969+ api .PatchConnectionRequest (
970+ connection_id = connection_id ,
971+ connection_patch_request = models .ConnectionPatchRequest (
972+ name = name ,
973+ configurations = configurations ,
974+ schedule = schedule ,
975+ prefix = prefix ,
976+ status = status ,
977+ ),
978+ ),
979+ )
980+ if status_ok (response .status_code ) and response .connection_response :
981+ return response .connection_response
982+
983+ raise AirbyteError (
984+ message = "Could not update connection." ,
985+ context = {
986+ "connection_id" : connection_id ,
987+ },
988+ response = response ,
989+ )
990+
991+
818992# Functions for leveraging the Airbyte Config API (may not be supported or stable)
819993
820994
0 commit comments