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.0.tar.gz
(4.2 kB
view hashes)
Built Distribution
Close
Hashes for compose_py-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe1b692838a6f4812e8e1837cfb9eb2468bff97f6e395cbe5c9468b0239a2937 |
|
MD5 | 895f40ec4a87059ae7ad8db3325b5ada |
|
BLAKE2b-256 | dbe4f583c29b1ce861c9183ba739253ad2ebcbfd8bf2be787f4ba08b7a634b3d |