A Python library for parsing and loading Compose files
Project description
compose-py
A Python library for parsing and loading Compose files
Installation
pip install compose-py
By default, the library doesn't have any dependencies for dataclass libraries.
Choose 'pydantic' or 'dataclasses' and install the library.
We also provide extras
for the libraries:
# If you prefer Pydantic models
pip install "compose-py[pydantic]"
# If you prefer dataclasses models
pip install "compose-py[dataclasses]"
Tutorial: Load, modify, and save docker-compose.yml
Pydantic.BaseModel (default)
import compose_py
obj = compose_py.load_yaml("docker-compose.yml")
print(obj) # Prints 'compose_py.models_pydantic.ComposeSpecification(...)'
print(obj.services["web"]) # Prints 'compose_py.models_pydantic.Service(...)'
# Copy and modify the existing service, then add it to the specification
web2 = obj.services["web"].copy()
web2.command = '--port 8081'
obj.services["web2"] = web2
compose_py.dump_yaml(obj, "docker-compose-modified.yml")
You can find more APIs under compose_py.models_pydantic
package.
dataclasses.dataclass
import compose_py
obj = compose_py.load_yaml("docker-compose.yml", model=compose_py.ModelType.DATACLASSES)
print(obj) # Prints 'compose_py.models_dataclasses.ComposeSpecification(...)'
print(obj.services["web"]) # Prints 'compose_py.models_dataclasses.Service(...)'
# Copy and modify the existing service, then add it to the specification
web2 = obj.services["web"].copy()
web2.command = '--port 8081'
obj.services["web2"] = web2
compose_py.dump_yaml(obj, "docker-compose-modified.yml", model=compose_py.ModelType.DATACLASSES)
You can find more APIs under compose_py.models_dataclasses
package.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
compose-py-0.1.1.tar.gz
(9.7 kB
view details)
Built Distribution
File details
Details for the file compose-py-0.1.1.tar.gz
.
File metadata
- Download URL: compose-py-0.1.1.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71c891b4999a7ee42a6fb7ffd441ee962460f80e854e6b9491f636aae03e0d79 |
|
MD5 | dd36235f796431b69cb447cf1de72b1d |
|
BLAKE2b-256 | 969337d95d4c480b9e65e9dbd75e82797b5c685dcfd8958b6eff42532522437c |
File details
Details for the file compose_py-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: compose_py-0.1.1-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4804ee365d2e997cce66e0483bb85d97784749b400868f0b841cab4015fe4ebf |
|
MD5 | 3bfb4d0771f42461f528995c7d32f16d |
|
BLAKE2b-256 | 3b2c987b6a915f257c29ec84ef6c1e9c55951be6cf9afd61a031a23f03fb9540 |