Skip to content

Podman pods

Don't use the constructor directly. Instead use

from python_on_whales import DockerClient

podman = DockerClient(client_call=["podman"])

my_pod = podman.pod.inspect("my-pod-name")

# or

my_pod = podman.pod.create("my-pod-name")

For type hints, use this

from python_on_whales import Pod

def print_container_names(pod: Pod):
    print([ctr.name for ctr in pod.containers])

Attributes

The attributes are the same that you get with the command line: podman pod inspect ...

If you want to know the exact structure, you can go to the podman pod inspect reference page

An example is worth many lines of descriptions.

In [1]: from python_on_whales import DockerClient

In [2]: podman = DockerClient(client_call=["podman"])

In [3]: pod = podman.pod.create("my-pod")

In [4]: def super_print(obj):
   ...:     print(f"type={type(obj)}, value={obj}")
   ...:

In [5]: super_print(pod.id)
type = <class 'str'>, value = da24a6717dfedebe91f51db09f91d7dde0eea93f1c76590a341e208affefdea7

In [6]: super_print(pod.name)
type = <class 'str'>, value = my-pod

In [7]: super_print(pod.created)
type = <class 'datetime.datetime'>, value = 2024-09-06 10:23:54.264234+00:00

In [8]: super_print(pod.state)
type = <class 'str'>, value = Created

In [9]: super_print(pod.num_containers)
type = <class 'int'>, value = 1

In [10]: super_print(pod.infra_container_id)
type = <class 'str'>, value = d7974a85b1ed9c0f53c20466197267a4dce6b466c10be3d68cd62ec16a41e28e

In [11]: super_print(pod.shared_namespaces)
type = <class 'list'>, value = ['uts', 'ipc', 'net']

In [12]: super_print(pod.hostname)
type = <class 'str'>, value = 

In [13]: super_print(pod.exit_policy)
type = <class 'NoneType'>, value = None

Methods

Pod

exists

exists()

Returns True if the pod exists and False if not.

See the podman.pod.exists command for information about the arguments.

kill

kill(*, signal=None)

Kill this pod

See the podman.pod.kill command for information about the arguments.

logs

logs(container=None, *, names=False, since=None, tail=None, timestamps=False, until=None, follow=False, stream=False)

Returns the logs of the pod containers

See the podman.pod.logs command for information about the arguments.

pause

pause()

Pause this pod.

See the podman.pod.pause command for information about the arguments.

remove

remove(*, force=False, time=None)

Remove this pod.

See the podman.pod.remove command for information about the arguments.

restart

restart()

Restart this pod.

See the podman.pod.restart command for information about the arguments.

start

start()

Starts this pod.

See the podman.pod.start command for information about the arguments.

stop

stop(*, time=None)

Stops this pod.

See the podman.pod.stop command for information about the arguments.

unpause

unpause()

Unpause the pod

See the podman.pod.unpause command for information about the arguments.