<p>I am looking for the python Kubernetes client equivalent for</p>
<pre><code>kubectl get deploy -n app -l team=blue
</code></pre>
<p>I'm aware of this function <code>deployment = api.read_namespaced_deployment(name='foo', namespace='bar')</code> but how can I have same thing with label?</p>

<p><code>read_namespaced_deployment</code> expects deployment name, which does not make sense of using <code>label</code>, you should use <a href="https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/AppsV1Api.md#list_namespaced_deployment" rel="nofollow noreferrer">list_namespaced_deployment</a></p>
<p>you can use <code>label_selector</code></p>
<blockquote>
<p><code>:param str label_selector</code>: A selector to restrict the list of returned objects by their labels. Defaults to everything.</p>
</blockquote>
<pre class="lang-py prettyprint-override"><code>from kubernetes import client, config
config.load_kube_config()
kube_client = client.AppsV1Api()
resp = kube_client.list_namespaced_deployment(namespace=&quot;app&quot;, label_selector=&quot;team=blue&quot;)
for deployment in resp.items:
    print(deployment)
</code></pre>
<p>to get all label</p>
<pre><code> kubectl get deployment --show-labels
</code></pre>
