<p>In python k8s client, i use below code</p>
<p>yaml file</p>
<pre><code>apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
    name: test-snapshot
    namespace: test
spec:
    volumeSnapshotClassName: snapshotclass
source:
    persistentVolumeClaimName: test-pvc
</code></pre>
<p>python code</p>
<pre><code>res = utils.create_from_dict(k8s_client, yaml_file)
</code></pre>
<p>However, i got this message:</p>
<pre><code>AttributeError: module 'kubernetes.client' has no attribute 'SnapshotStorageV1Api'
</code></pre>
<p>I want to take a volumesnapshot in k8s.
How can i do that?</p>
<p>Please give me some advices!</p>

<p>As I pointed in part of the comment I made under the question:</p>
<blockquote>
<p>Have you seen this github issue comment: <a href="https://github.com/kubernetes-client/python/issues/1195#issuecomment-699510580" rel="nofollow noreferrer">github.com/kubernetes-client/python/issues/…</a>?</p>
</blockquote>
<p>The link posted in the comments is a github issue for:</p>
<ul>
<li><code>VolumeSnapshot</code>,</li>
<li><code>VolumeSnapshotClass</code>,</li>
<li><code>VolumeSnapshotContent</code></li>
</ul>
<p>support in the Kubernetes python client.</p>
<p>Citing the comment made in this github issue by user @roycaihw that explains a way how you can make a snapshot:</p>
<blockquote>
<p>It looks like those APIs are CRDs: <a href="https://kubernetes.io/docs/concepts/storage/volume-snapshot-classes/#the-volumesnapshotclass-resource" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/storage/volume-snapshot-classes/#the-volumesnapshotclass-resource</a></p>
<p>If that's the case, you could use the CustomObject API to send requests to those APIs once they are installed. Example: <a href="https://github.com/kubernetes-client/python/blob/master/examples/custom_object.py" rel="nofollow noreferrer">https://github.com/kubernetes-client/python/blob/master/examples/custom_object.py</a></p>
<p>-- <em><a href="https://github.com/kubernetes-client/python/issues/1195#issuecomment-662190528" rel="nofollow noreferrer">Github.com: Kubernetes client: Python: Issues: 1995: Issue comment: 2</a></em></p>
</blockquote>
<hr />
<h3>Example</h3>
<p>An example of a Python code that would make a <code>VolumeSnapshot</code> is following:</p>
<pre class="lang-py prettyprint-override"><code>from kubernetes import client, config


def main():
    config.load_kube_config()

    api = client.CustomObjectsApi()

    # it's my custom resource defined as Dict
    my_resource = {
        &quot;apiVersion&quot;: &quot;snapshot.storage.k8s.io/v1beta1&quot;,
        &quot;kind&quot;: &quot;VolumeSnapshot&quot;,
        &quot;metadata&quot;: {&quot;name&quot;: &quot;python-snapshot&quot;},
        &quot;spec&quot;: {
            &quot;volumeSnapshotClassName&quot;: &quot;example-snapshot-class&quot;,
            &quot;source&quot;: {&quot;persistentVolumeClaimName&quot;: &quot;example-pvc&quot;}
                }
    }

    # create the resource
    api.create_namespaced_custom_object(
        group=&quot;snapshot.storage.k8s.io&quot;,
        version=&quot;v1beta1&quot;,
        namespace=&quot;default&quot;,
        plural=&quot;volumesnapshots&quot;,
        body=my_resource,
    )

if __name__ == &quot;__main__&quot;:
    main()
</code></pre>
<p><strong>Please change the values inside of this code to support your particular setup (i.e. <code>apiVersion</code>, <code>.metadata.name</code>, <code>.metadata.namespace</code>, etc.).</strong></p>
<blockquote>
<p>A side note!</p>
<p>This Python code was tested with <code>GKE</code> and it's <code>gce-pd-csi-driver</code>.</p>
</blockquote>
<p>After running this code the <code>VolumeSnapshot</code> should be created:</p>
<ul>
<li><code>$ kubectl get volumesnapshots</code></li>
</ul>
<pre class="lang-sh prettyprint-override"><code>NAME               AGE
python-snapshot    19m
</code></pre>
<ul>
<li><code>$ kubectl get volumesnapshotcontents</code></li>
</ul>
<pre class="lang-sh prettyprint-override"><code>NAME                                               AGE
snapcontent-71380980-6d91-45dc-ab13-4b9f42f7e7f2   19m
</code></pre>
<hr />
<p>Additional resources:</p>
<ul>
<li><em><a href="https://github.com/kubernetes-client/python" rel="nofollow noreferrer">Github.com: Kubernetes client: Python</a></em></li>
<li><em><a href="https://kubernetes.io/docs/concepts/storage/volume-snapshots/" rel="nofollow noreferrer">Kubernetes.io: Docs: Concepts: Storage: Volume snapshots</a></em></li>
</ul>
