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.
Examples
See examples/ directory to find examples.
Metadata
Release files for compose-py 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| compose-py-0.3.0.tar.gz | 9.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| compose_py-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.2 kB
Release files / compose-py-0.3.0.tar.gz
| Download URL | compose-py-0.3.0.tar.gz |
|---|---|
| Size | 9.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
83e69487bb315f45dcdc4b862cae9bec40545675616cd1dcae938715645c5800
|
|
BLAKE2b-256 checksum How to use checksums |
ee8e64bd40f1b2e54dd0845fd5f243021ae493a787372853bea5324cdd1d772a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.15
|
Release files / compose_py-0.3.0-py3-none-any.whl
| Download URL | compose_py-0.3.0-py3-none-any.whl |
|---|---|
| Size | 13.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
86029436cb79f62972d697cf228abe5c9e7a15b7585879d95e8ec96a9d622c9b
|
|
BLAKE2b-256 checksum How to use checksums |
aa987758b62352b53479a4c31e2e9d2f13b629197d6d04a64fd5888a7021012e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.15
|