Use the APIClient.update_service method to modify a service. This method requires a version argument to prevent concurrent write conflicts; this version index must be retrieved first via APIClient.inspect_service from the ['Version']['Index'] key. You can update parameters like name and task_template.
container_spec = docker.types.ContainerSpec(
image='busybox', command=['echo', 'hello world']
)
task_tmpl = docker.types.TaskTemplate(container_spec)
svc_version = client.inspect_service(svc_id)['Version']['Index']
client.update_service(
svc_id, svc_version, name='new_name', task_template=task_tmpl
)