How to pass cloud init yaml via API as config?

I am looking for the API equivalent of doing the below.

lxc launch ubuntu1804 test"$(cat network-config.yaml)"

I am using pylxd client and while creating a container I can pass a config dictionary.
How do I pass a yaml as a value to the in config object?

Yaml looks like:

version: 1
  - type: physical
    name: eth0
      - type: static
        address: <ip-address>
        gateway: <ip-address>
          - <ip-address>
          - <ip-address>

You have to create the container first, and then apply the cloud-init config to the container’s “config” dict. I’m using lxd 3.13 and pylxd 2.2.6 as of this writing.
Here’s the way I do it. “netconf” is a dict in the format as this example {“eth0”: “”}

	for ifname, nwstr in netconf.items():
		if not '/' in nwstr:
			nwstr = "%s/%d" % (nwstr, 24)
		ic = ipaddress.ip_interface(nwstr)
		gw = ipaddress.ip_address( + 1).compressed
		dns.append(ipaddress.ip_address( + 2).compressed)
		networks.append({'type': 'physical', 'name': ifname, 'subnets':
				'type': 'static',
				'address': ic.compressed,
				'gateway': gw,

	nwconfig = yaml.dump({'version': 1, 'config': networks})

cont = client.containers.create(config, wait=True)
# have to create() before setting cloud-init config for some unfathomable reason
cont.config[''] = nwconfig