<p>How to <em>list all</em> certificates &amp; make a <em>describe</em> in the particular namespaces using <a href="https://github.com/kubernetes-client/python/tree/release-18.0" rel="nofollow noreferrer">kubernetes python cli</a>?</p>
<pre><code># list certificates
kubectl get certificates -n my-namespace

# describe a certificate
kubectl describe certificate my-certificate -n my-namespace
</code></pre>

<p>Kubernetes by default doesn't have a kind <code>certificate</code>, you must first install <a href="https://cert-manager.io/docs/" rel="nofollow noreferrer">cert-manager's</a> <code>CustomResourceDefinition</code>.</p>
<p>Considering the above means that in Kuberentes Python client we must use <a href="https://github.com/kubernetes-client/python/blob/8a36dfb113868862d9ef8fd0a44b1fb7621c463a/kubernetes/client/api/custom_objects_api.py" rel="nofollow noreferrer">custom object API</a>, especially in your case: functions <code>list_namespaced_custom_object()</code> and <code>get_namespaced_custom_object()</code>.</p>
<p>Below code has two functions, one is returning all certificates (equivalent to the <code>kubectl get certificates</code> command), the second one is returning information about one specific certificate (equivalent to the <code>kubectl describe certificate {certificate-name}</code> command). Based on <a href="https://github.com/kubernetes-client/python/blob/8a36dfb113868862d9ef8fd0a44b1fb7621c463a/examples/namespaced_custom_object.py" rel="nofollow noreferrer">this example code</a>:</p>
<pre class="lang-py prettyprint-override"><code>from kubernetes import client, config

config.load_kube_config()
api = client.CustomObjectsApi()

# kubectl get certificates -n my-namespace
def list_certificates():
    resources = api.list_namespaced_custom_object(
        group = &quot;cert-manager.io&quot;,
        version = &quot;v1&quot;,
        namespace = &quot;my-namespace&quot;,
        plural = &quot;certificates&quot;
    )
    return resources

# kubectl describe certificate my-certificate -n my-namespace
def get_certificate():
    resource = api.get_namespaced_custom_object(
        group = &quot;cert-manager.io&quot;,
        version = &quot;v1&quot;,
        name = &quot;my-certificate&quot;,
        namespace = &quot;my-namespace&quot;,
        plural = &quot;certificates&quot;
    )
    return resource
</code></pre>
<p>Keep in mind that both functions are returning <a href="https://www.w3schools.com/python/python_dictionaries.asp" rel="nofollow noreferrer">Python dictionaries</a>.</p>
