Secrets with python api

I’m developing an application using the docker api with python3 using Docker Desktop for Mac (2.1.0.4). So far everything is working great but I need to provide passwords to the container using docker secrets. Swarm is running and I am able to create services. The problem I’m having is that the documentation indicates that to specify a secret the code needs to provide a list of “SecretReference” class objects. Where are SecretReference objects stored and how do I access them? I’m able to list and view the stored secrets in my swarm using the apis client.secrets.list() and client.secrets.get() but I have been unable to start the container service with any combination of values returned from these. I’ve looked at the documentation for the SecretReference class but it wasn’t helpful to me. How do I provide specific docker secrets to the service I’m creating?
Below is a brief code example that shows what I’m working with:

#!/usr/bin/env python3

import docker, getpass
client = docker.from_env()
my_pw = getpass.getpass(prompt='Password: ')

client.secrets.create(name='new_pw',
                      data=str.encode(my_pw))

client.services.create('ubuntu:latest',
                       name='TestSvc',
                       hostname='test_host',
                       secrets=['new_pw']
)

If this is not an appropriate forum for this question then please let me know so that I can move my request.

Well, in case anyone finds this helpful, I worked out how to get this functional:

#!/usr/bin/env python3

import docker, getpass

client = docker.from_env()

my_pw = getpass.getpass(prompt='Password: ')

sec_name = 'TestSec'
noise = client.secrets.create(name=sec_name,  
                              data=str.encode(my_pw))
secret_id = client.secrets.list(filters={'name': sec_name})[0].id

secRef = docker.types.SecretReference(secret_id, sec_name)

print(type(secRef))

client.services.create('alpine:latest',
                       name='TestSvc',
                       hostname='test_host',
                       secrets=[secRef],
                       command='sleep 999',)