Pyo3ComposeProject

Struct Pyo3ComposeProject 

Source
pub struct Pyo3ComposeProject { /* private fields */ }
Expand description

Manages a Docker Compose project for orchestrating multi-container deployments.

A ComposeProject represents a running or potential deployment of a Compose file. It provides methods to bring services up (create and start) or down (stop and remove).

Example: >>> docker = Docker() >>> compose = parse_compose_file(“docker-compose.yml”) >>> project = ComposeProject(docker, compose, “myproject”) >>> project.up() # Create networks, volumes, and start containers >>> project.down() # Stop and remove containers

Implementations§

Source§

impl Pyo3ComposeProject

Source

pub fn new( docker: Pyo3Docker, compose: Pyo3ComposeFile, project_name: &str, ) -> Self

Create a new ComposeProject.

Args: docker: Docker client instance compose: Parsed ComposeFile instance project_name: Name for this project (used as prefix for resources)

Returns: ComposeProject: Project instance ready for up/down operations

Source

pub fn get_project_name(&self) -> String

Get the project name.

Returns: str: Project name

Source

pub fn up(&self, py: Python<'_>, detach: Option<bool>) -> PyResult<Py<PyAny>>

Bring up the compose project.

Creates networks, volumes, and containers defined in the compose file, then starts the containers.

Args: detach: Run containers in the background (default: True)

Returns: dict: Results including created network IDs, volume names, and container IDs

Raises: RuntimeError: If any operation fails

Source

pub fn down( &self, py: Python<'_>, remove_volumes: Option<bool>, remove_networks: Option<bool>, timeout: Option<u64>, ) -> PyResult<Py<PyAny>>

Bring down the compose project.

Stops and removes containers, and optionally removes networks and volumes.

Args: remove_volumes: Also remove named volumes (default: False) remove_networks: Also remove networks (default: True) timeout: Timeout in seconds for stopping containers (default: 10)

Returns: dict: Results including stopped/removed container IDs, network IDs, volume names

Raises: RuntimeError: If any operation fails

Source

pub fn ps(&self) -> PyResult<Vec<String>>

List containers for this project.

Returns: liststr: List of container IDs belonging to this project

Source

pub fn start(&self) -> PyResult<Vec<String>>

Start all stopped containers in the project.

Starts containers that were previously stopped without recreating them.

Returns: liststr: List of container IDs that were started

Raises: RuntimeError: If any container fails to start

Source

pub fn stop(&self, timeout: Option<u64>) -> PyResult<Vec<String>>

Stop all running containers in the project.

Stops containers without removing them.

Args: timeout: Timeout in seconds to wait for containers to stop (default: 10)

Returns: liststr: List of container IDs that were stopped

Raises: RuntimeError: If any container fails to stop

Source

pub fn restart(&self, timeout: Option<u64>) -> PyResult<Vec<String>>

Restart all containers in the project.

Restarts all containers without recreating them.

Args: timeout: Timeout in seconds to wait for containers to stop before restart (default: 10)

Returns: liststr: List of container IDs that were restarted

Raises: RuntimeError: If any container fails to restart

Source

pub fn pause(&self) -> PyResult<Vec<String>>

Pause all running containers in the project.

Pauses all processes within the containers.

Returns: liststr: List of container IDs that were paused

Raises: RuntimeError: If any container fails to pause

Source

pub fn unpause(&self) -> PyResult<Vec<String>>

Unpause all paused containers in the project.

Resumes all processes within the containers.

Returns: liststr: List of container IDs that were unpaused

Raises: RuntimeError: If any container fails to unpause

Source

pub fn pull(&self) -> PyResult<Vec<String>>

Pull images for all services in the project.

Pulls the images specified in the compose file for all services that have an image field defined.

Returns: liststr: List of images that were pulled

Raises: RuntimeError: If any image fails to pull

Source

pub fn build( &self, no_cache: Option<bool>, pull: Option<bool>, ) -> PyResult<Vec<String>>

Build images for all services in the project that have a build config.

Builds images for services that have a build field defined in the compose file. Services with only an image field are skipped.

Args: no_cache: Do not use cache when building (default: False) pull: Always pull newer versions of base images (default: False)

Returns: liststr: List of services that were built

Raises: RuntimeError: If any build fails

Source

pub fn push(&self) -> PyResult<Vec<String>>

Push images for all services in the project.

Pushes images for services that have an image field defined to their registry.

Returns: liststr: List of images that were pushed

Raises: RuntimeError: If any image fails to push

Source

pub fn ps_detailed(&self, py: Python<'_>) -> PyResult<Py<PyAny>>

Get detailed information about containers in the project.

Returns detailed information about each container including ID, name, state, service name, and image.

Returns: list[dict]: List of container info dicts with keys: - id: Container ID - name: Container name - service: Service name from compose file - state: Container state (running, stopped, etc.) - status: Container status message - image: Image used by the container

Raises: RuntimeError: If container information cannot be retrieved

Source

pub fn logs( &self, py: Python<'_>, service: Option<&str>, tail: Option<usize>, timestamps: Option<bool>, ) -> PyResult<Py<PyAny>>

Get logs from all containers in the project.

Collects logs from all containers belonging to this project.

Args: service: Only get logs from this service (optional) tail: Number of lines to show from the end of logs (optional) timestamps: Include timestamps in output (default: False)

Returns: dict[str, str]: Mapping of container ID to its logs

Raises: RuntimeError: If logs cannot be retrieved

Source

pub fn config(&self, py: Python<'_>) -> PyResult<Py<PyAny>>

Get the compose configuration as a dictionary.

Returns the parsed compose file configuration, useful for inspecting the services, networks, and volumes defined in the project.

Returns: dict: The compose file configuration

Source

pub fn top(&self, py: Python<'_>, ps_args: Option<&str>) -> PyResult<Py<PyAny>>

Get running processes from all containers in the project.

Returns process information from all running containers in the project.

Args: ps_args: Arguments to pass to ps command (e.g., “aux”)

Returns: dict[str, dict]: Mapping of container ID to its process info

Raises: RuntimeError: If process information cannot be retrieved

Source

pub fn exec( &self, service: &str, command: Vec<String>, user: Option<&str>, workdir: Option<&str>, env: Option<Vec<String>>, privileged: Option<bool>, tty: Option<bool>, ) -> PyResult<String>

Execute a command in a running service container.

Runs a command in the first running container of the specified service, similar to docker-compose exec.

Args: service: Name of the service to execute the command in command: Command to execute as a list (e.g., [“ls”, “-la”]) user: User to run the command as (optional) workdir: Working directory inside the container (optional) env: Environment variables as a list (e.g., [“VAR=value”]) (optional) privileged: Give extended privileges to the command (default: False) tty: Allocate a pseudo-TTY (default: False)

Returns: str: Output from the executed command

Raises: RuntimeError: If no running container is found for the service RuntimeError: If command execution fails

Source

pub fn run( &self, py: Python<'_>, service: &str, command: Option<Vec<String>>, user: Option<&str>, workdir: Option<&str>, env: Option<Vec<String>>, rm: Option<bool>, detach: Option<bool>, ) -> PyResult<Py<PyAny>>

Run a one-off command in a new container for a service.

Creates a new container based on the service configuration, runs the specified command, and optionally removes the container afterward. Similar to docker-compose run.

Args: service: Name of the service to run command: Command to execute as a list (e.g., [“python”, “script.py”]). If not provided, uses the service’s default command. user: User to run the command as (optional) workdir: Working directory inside the container (optional) env: Additional environment variables as a list (e.g., [“VAR=value”]) rm: Remove the container after exit (default: True) detach: Run container in the background (default: False)

Returns: dict: Result containing container_id and output (if not detached)

Raises: RuntimeError: If the service is not found in the compose file RuntimeError: If container creation or execution fails

Trait Implementations§

Source§

impl Debug for Pyo3ComposeProject

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'py> IntoPyObject<'py> for Pyo3ComposeProject

Source§

type Target = Pyo3ComposeProject

The Python output type
Source§

type Output = Bound<'py, <Pyo3ComposeProject as IntoPyObject<'py>>::Target>

The smart pointer type to use. Read more
Source§

type Error = PyErr

The type returned in the event of a conversion error.
Source§

fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>

Performs the conversion.
Source§

impl PyClass for Pyo3ComposeProject

Source§

type Frozen = False

Whether the pyclass is frozen. Read more
Source§

impl PyClassImpl for Pyo3ComposeProject

Source§

const IS_BASETYPE: bool = false

#[pyclass(subclass)]
Source§

const IS_SUBCLASS: bool = false

#[pyclass(extends=…)]
Source§

const IS_MAPPING: bool = false

#[pyclass(mapping)]
Source§

const IS_SEQUENCE: bool = false

#[pyclass(sequence)]
Source§

const IS_IMMUTABLE_TYPE: bool = false

#[pyclass(immutable_type)]
Source§

const RAW_DOC: &'static CStr = /// Manages a Docker Compose project for orchestrating multi-container deployments. /// /// A ComposeProject represents a running or potential deployment of a Compose file. /// It provides methods to bring services up (create and start) or down (stop and remove). /// /// Example: /// >>> docker = Docker() /// >>> compose = parse_compose_file("docker-compose.yml") /// >>> project = ComposeProject(docker, compose, "myproject") /// >>> project.up() # Create networks, volumes, and start containers /// >>> project.down() # Stop and remove containers

Docstring for the class provided on the struct or enum. Read more
Source§

const DOC: &'static CStr

Fully rendered class doc, including the text_signature if a constructor is defined. Read more
Source§

type BaseType = PyAny

Base class
Source§

type ThreadChecker = SendablePyClass<Pyo3ComposeProject>

This handles following two situations: Read more
Source§

type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild

Immutable or mutable
Source§

type Dict = PyClassDummySlot

Specify this class has #[pyclass(dict)] or not.
Source§

type WeakRef = PyClassDummySlot

Specify this class has #[pyclass(weakref)] or not.
Source§

type BaseNativeType = PyAny

The closest native ancestor. This is PyAny by default, and when you declare #[pyclass(extends=PyDict)], it’s PyDict.
Source§

fn items_iter() -> PyClassItemsIter

Source§

fn lazy_type_object() -> &'static LazyTypeObject<Self>

Source§

fn dict_offset() -> Option<isize>

Source§

fn weaklist_offset() -> Option<isize>

Source§

impl PyClassNewTextSignature for Pyo3ComposeProject

Source§

const TEXT_SIGNATURE: &'static str = "(docker, compose, project_name)"

Source§

impl PyMethods<Pyo3ComposeProject> for PyClassImplCollector<Pyo3ComposeProject>

Source§

fn py_methods(self) -> &'static PyClassItems

Source§

impl PyTypeInfo for Pyo3ComposeProject

Source§

const NAME: &'static str = "ComposeProject"

Class name.
Source§

const MODULE: Option<&'static str> = ::core::option::Option::None

Module name, if any.
Source§

fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject

Returns the PyTypeObject instance for this type.
Source§

fn type_object(py: Python<'_>) -> Bound<'_, PyType>

Returns the safe abstraction over the type object.
Source§

fn is_type_of(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type or a subclass of this type.
Source§

fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type.
Source§

impl DerefToPyAny for Pyo3ComposeProject

Source§

impl ExtractPyClassWithClone for Pyo3ComposeProject

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<'py, T> IntoPyObjectExt<'py> for T
where T: IntoPyObject<'py>,

Source§

fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>

Converts self into an owned Python object, dropping type information.
Source§

fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>

Converts self into an owned Python object, dropping type information and unbinding it from the 'py lifetime.
Source§

fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>

Converts self into a Python object. Read more
Source§

impl<T> PyErrArguments for T
where T: for<'py> IntoPyObject<'py> + Send + Sync,

Source§

fn arguments(self, py: Python<'_>) -> Py<PyAny>

Arguments for exception
Source§

impl<T> PyTypeCheck for T
where T: PyTypeInfo,

Source§

const NAME: &'static str = T::NAME

👎Deprecated since 0.27.0: Use ::classinfo_object() instead and format the type name at runtime. Note that using built-in cast features is often better than manual PyTypeCheck usage.
Name of self. This is used in error messages, for example.
Source§

fn type_check(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of Self, which may include a subtype. Read more
Source§

fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>

Returns the expected type as a possible argument for the isinstance and issubclass function. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Ungil for T
where T: Send,