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
with open("docker-compose.yml", "r") as f:
obj = compose_py.load_yaml(f)
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
print(compose_py.dump_yaml_str(obj))
with open("docker-compose-modified.yml", "w") as f:
compose_py.dump_yaml(obj, f)
You can find more APIs under compose_py.models_pydantic
package.
dataclasses.dataclass
import compose_py
with open("docker-compose.yml", "r") as f:
obj = compose_py.load_yaml(f, 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
print(compose_py.dump_yaml_str(obj))
with open("docker-compose-modified.yml", "w") as f:
compose_py.dump_yaml(obj, f, 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.2.0.tar.gz
(9.8 kB
view details)
Built Distribution
File details
Details for the file compose-py-0.2.0.tar.gz
.
File metadata
- Download URL: compose-py-0.2.0.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15acb76769c47170d5c9de1e922cce1681dbdcca2a67b17fb27aa2d269a7271b |
|
MD5 | 854fdc9b545512c42322182c5d7910e1 |
|
BLAKE2b-256 | 90a72fed401d3a170e5390502e7f4a950ec936aca61cadcc0179be72a5a0948d |
File details
Details for the file compose_py-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: compose_py-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fcd359087b5d4e20b5d7fe6e8610f53f10af6532824c57bc1b077b3865fd600 |
|
MD5 | 6c9931d7b0c3c8871f9e9cc6a4d133af |
|
BLAKE2b-256 | 53ccf311d337d8a3327ec42f56d9e317681db2e48bf127353e5bb95ee073ace7 |