<p>With kubectl, I know i can run below command if I want to see specific resources YAML file</p>
<pre><code>kubectl -n &lt;some namespace&gt; get &lt;some resource&gt; &lt;some resource name&gt; -o yaml
</code></pre>
<p>How would I get this same data using python's kubernetes-client ?
Everything I've found so far only talks about creating a resource from a given yaml file.</p>
<p>In looking at <a href="https://github.com/kubernetes-client/python/blob/master/kubernetes/README.md" rel="nofollow noreferrer">docs</a>, I noticed that each resource type generally has a <strong>get_api_resources()</strong> function which returns a <a href="https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/V1APIResourceList.md" rel="nofollow noreferrer">V1ApiResourceList</a>, where each item is a <a href="https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/V1APIResource.md" rel="nofollow noreferrer">V1ApiResource</a>.  I was hoping there would be a way to get the resource's yaml-output by using a V1ApiResource object, but doesnt appear like that's the way to go about it.</p>
<p>Do you all have any suggestions ?  Is this possible with kubernetes-client API ?</p>

<p>If you take a look at the methods available on an object, e.g.:</p>
<pre><code>&gt;&gt;&gt; import kubernetes.config
&gt;&gt;&gt; client = kubernetes.config.new_client_from_config()
&gt;&gt;&gt; core = kubernetes.client.CoreV1Api(client)
&gt;&gt;&gt; res = core.read_namespace('kube-system')
&gt;&gt;&gt; dir(res)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_api_version', '_kind', '_metadata', '_spec', '_status', 'api_version', 'attribute_map', 'discriminator', 'kind', 'local_vars_configuration', 'metadata', 'openapi_types', 'spec', 'status', 'to_dict', 'to_str']
</code></pre>
<p>...you'll see there is a <code>to_dict</code> method. That returns the object as
a dictionary, which you can then serialize to YAML or JSON or
whatever:</p>
<pre><code>&gt;&gt;&gt; import yaml
&gt;&gt;&gt; print(yaml.safe_dump(res.to_dict()))
api_version: v1
kind: Namespace
metadata:
[...]
</code></pre>
