# compose-pydantic
Parse `Compose Specification` YAML using `Pydantic` and `PyYAML`.
## Description
This library works as a thin layer on top of `pydantic`. It's purpose is to convert YAML to Python objects.
The python model is generated using `datamodel-codegen` and the `Compose Specification` JSON schema URI.
```bash
datamodel-codegen \
--input-file-type jsonschema \
--url https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json \
--output compose_pydantic/models.py
```
## Getting Started
### Dependencies
* pydantic==1.9.0
* PyYAML>=6.0
* mergedeep>=1.3.4
### Installation
```bash
pip install compose-pydantic
```
### Usage
Read multiple compose files
```python
from compose_pydantic import ComposeSpecificationFactory
csf = ComposeSpecificationFactory()
compose = csf(source='tests/compose/docker-compose.yml', overrides=['tests/compose/docker-compose.override.yml'])
print(compose.__dict__)
```
Result:
```python
{'version': '3.9', 'name': None, 'services': {'db': Service(deploy=None, build=None, blkio_config=None, cap_add=None, cap_drop=None, cgroup_parent=None, command=None, configs=None, container_name=None, cpu_count=None, cpu_percent=None, cpu_shares=None, cpu_quota=None, cpu_period=None, cpu_rt_period=None, cpu_rt_runtime=None, cpus=None, cpuset=None, credential_spec=None, depends_on=None, device_cgroup_rules=None, devices=None, dns=None, dns_opt=None, dns_search=None, domainname=None, entrypoint=None, env_file=None, environment=ListOrDict(__root__=['POSTGRES_NAME=devpostgres', 'POSTGRES_USER=devpostgres', 'POSTGRES_PASSWORD=devpostgres']), expose=None, extends=None, external_links=None, extra_hosts=None, group_add=None, healthcheck=None, hostname=None, image='postgres', init=None, ipc=None, isolation=None, labels=None, links=None, logging=None, mac_address=None, mem_limit=None, mem_reservation=None, mem_swappiness=None, memswap_limit=None, network_mode=None, networks=None, oom_kill_disable=None, oom_score_adj=None, pid=None, pids_limit=None, platform=None, ports=None, privileged=None, profiles=None, pull_policy=None, read_only=None, restart=None, runtime=None, scale=None, security_opt=None, shm_size=None, secrets=None, sysctls=None, stdin_open=None, stop_grace_period=None, stop_signal=None, storage_opt=None, tmpfs=None, tty=None, ulimits=None, user=None, userns_mode=None, volumes=['./data/db:/var/lib/postgresql/data'], volumes_from=None, working_dir=None), 'web': Service(deploy=None, build='.', blkio_config=None, cap_add=None, cap_drop=None, cgroup_parent=None, command='python manage.py runserver 0.0.0.0:8000', configs=None, container_name=None, cpu_count=None, cpu_percent=None, cpu_shares=None, cpu_quota=None, cpu_period=None, cpu_rt_period=None, cpu_rt_runtime=None, cpus=None, cpuset=None, credential_spec=None, depends_on=ListOfStrings(__root__=['db']), device_cgroup_rules=None, devices=None, dns=None, dns_opt=None, dns_search=None, domainname=None, entrypoint=None, env_file=None, environment=ListOrDict(__root__=['POSTGRES_NAME=devpostgres', 'POSTGRES_USER=devpostgres', 'POSTGRES_PASSWORD=devpostgres']), expose=None, extends=None, external_links=None, extra_hosts=None, group_add=None, healthcheck=None, hostname=None, image=None, init=None, ipc=None, isolation=None, labels=None, links=None, logging=None, mac_address=None, mem_limit=None, mem_reservation=None, mem_swappiness=None, memswap_limit=None, network_mode=None, networks=None, oom_kill_disable=None, oom_score_adj=None, pid=None, pids_limit=None, platform=None, ports=['8000:8000'], privileged=None, profiles=None, pull_policy=None, read_only=None, restart=None, runtime=None, scale=None, security_opt=None, shm_size=None, secrets=None, sysctls=None, stdin_open=None, stop_grace_period=None, stop_signal=None, storage_opt=None, tmpfs=None, tty=None, ulimits=None, user=None, userns_mode=None, volumes=['.:/code'], volumes_from=None, working_dir=None)}, 'networks': None, 'volumes': None, 'secrets': None, 'configs': None}
```
## Tests
If you're working with a clone of this repository, you can run tests like this:
```bash
$ make init test
```
See also `tests/test_lib.py` for the different ways you may use the factory class to access compose spec data.
## Authors
Alexandros Monastiriotis alexmondev@gmail.com
## Version History
* 0.2.0
* Change API
* 0.1.1
* Add missing dependency
* 0.1.0
* Initial Release
## License
This project is licensed under the MIT License - see the LICENSE file for details
## Acknowledgments
Inspiration, libraries, etc.
* [pydantic](https://github.com/samuelcolvin/pydantic/)
* [datamodel-code-generator](https://github.com/koxudaxi/datamodel-code-generator/)
* [Compose Specification](https://github.com/compose-spec/compose-spec)
* [PyYAML](https://github.com/yaml/pyyaml)
* [mergedeep](https://github.com/clarketm/mergedeep)
* [Understanding multiple Compose files](https://docs.docker.com/compose/extends/#multiple-compose-files)
Raw data
{
"_id": null,
"home_page": "https://github.com/alexmon/compose-pydantic",
"name": "compose-pydantic",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "Compose, Pydantic",
"author": "Alexandros Monastiriotis",
"author_email": "alexmondev@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/71/1d/d8e6f5984dfb0e863fa5a17d8a408b5c6292a952c7f718bfb9f622fab3b3/compose_pydantic-0.2.1.tar.gz",
"platform": null,
"description": "# compose-pydantic\n\nParse `Compose Specification` YAML using `Pydantic` and `PyYAML`.\n\n## Description\n\nThis library works as a thin layer on top of `pydantic`. It's purpose is to convert YAML to Python objects.\nThe python model is generated using `datamodel-codegen` and the `Compose Specification` JSON schema URI.\n```bash\ndatamodel-codegen \\\n --input-file-type jsonschema \\\n --url https://raw.githubusercontent.com/compose-spec/compose-spec/master/schema/compose-spec.json \\\n --output compose_pydantic/models.py\n```\n\n## Getting Started\n\n### Dependencies\n\n* pydantic==1.9.0\n* PyYAML>=6.0\n* mergedeep>=1.3.4\n\n### Installation\n\n```bash\npip install compose-pydantic\n```\n\n### Usage\n\nRead multiple compose files\n```python\nfrom compose_pydantic import ComposeSpecificationFactory\n\ncsf = ComposeSpecificationFactory()\ncompose = csf(source='tests/compose/docker-compose.yml', overrides=['tests/compose/docker-compose.override.yml'])\n\nprint(compose.__dict__)\n```\n\nResult:\n```python\n{'version': '3.9', 'name': None, 'services': {'db': Service(deploy=None, build=None, blkio_config=None, cap_add=None, cap_drop=None, cgroup_parent=None, command=None, configs=None, container_name=None, cpu_count=None, cpu_percent=None, cpu_shares=None, cpu_quota=None, cpu_period=None, cpu_rt_period=None, cpu_rt_runtime=None, cpus=None, cpuset=None, credential_spec=None, depends_on=None, device_cgroup_rules=None, devices=None, dns=None, dns_opt=None, dns_search=None, domainname=None, entrypoint=None, env_file=None, environment=ListOrDict(__root__=['POSTGRES_NAME=devpostgres', 'POSTGRES_USER=devpostgres', 'POSTGRES_PASSWORD=devpostgres']), expose=None, extends=None, external_links=None, extra_hosts=None, group_add=None, healthcheck=None, hostname=None, image='postgres', init=None, ipc=None, isolation=None, labels=None, links=None, logging=None, mac_address=None, mem_limit=None, mem_reservation=None, mem_swappiness=None, memswap_limit=None, network_mode=None, networks=None, oom_kill_disable=None, oom_score_adj=None, pid=None, pids_limit=None, platform=None, ports=None, privileged=None, profiles=None, pull_policy=None, read_only=None, restart=None, runtime=None, scale=None, security_opt=None, shm_size=None, secrets=None, sysctls=None, stdin_open=None, stop_grace_period=None, stop_signal=None, storage_opt=None, tmpfs=None, tty=None, ulimits=None, user=None, userns_mode=None, volumes=['./data/db:/var/lib/postgresql/data'], volumes_from=None, working_dir=None), 'web': Service(deploy=None, build='.', blkio_config=None, cap_add=None, cap_drop=None, cgroup_parent=None, command='python manage.py runserver 0.0.0.0:8000', configs=None, container_name=None, cpu_count=None, cpu_percent=None, cpu_shares=None, cpu_quota=None, cpu_period=None, cpu_rt_period=None, cpu_rt_runtime=None, cpus=None, cpuset=None, credential_spec=None, depends_on=ListOfStrings(__root__=['db']), device_cgroup_rules=None, devices=None, dns=None, dns_opt=None, dns_search=None, domainname=None, entrypoint=None, env_file=None, environment=ListOrDict(__root__=['POSTGRES_NAME=devpostgres', 'POSTGRES_USER=devpostgres', 'POSTGRES_PASSWORD=devpostgres']), expose=None, extends=None, external_links=None, extra_hosts=None, group_add=None, healthcheck=None, hostname=None, image=None, init=None, ipc=None, isolation=None, labels=None, links=None, logging=None, mac_address=None, mem_limit=None, mem_reservation=None, mem_swappiness=None, memswap_limit=None, network_mode=None, networks=None, oom_kill_disable=None, oom_score_adj=None, pid=None, pids_limit=None, platform=None, ports=['8000:8000'], privileged=None, profiles=None, pull_policy=None, read_only=None, restart=None, runtime=None, scale=None, security_opt=None, shm_size=None, secrets=None, sysctls=None, stdin_open=None, stop_grace_period=None, stop_signal=None, storage_opt=None, tmpfs=None, tty=None, ulimits=None, user=None, userns_mode=None, volumes=['.:/code'], volumes_from=None, working_dir=None)}, 'networks': None, 'volumes': None, 'secrets': None, 'configs': None}\n```\n\n## Tests\n\nIf you're working with a clone of this repository, you can run tests like this:\n\n```bash\n$ make init test\n```\n\nSee also `tests/test_lib.py` for the different ways you may use the factory class to access compose spec data.\n\n## Authors\n\nAlexandros Monastiriotis alexmondev@gmail.com\n\n## Version History\n\n* 0.2.0\n * Change API\n* 0.1.1\n * Add missing dependency\n* 0.1.0\n * Initial Release\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details\n\n## Acknowledgments\n\nInspiration, libraries, etc.\n* [pydantic](https://github.com/samuelcolvin/pydantic/)\n* [datamodel-code-generator](https://github.com/koxudaxi/datamodel-code-generator/)\n* [Compose Specification](https://github.com/compose-spec/compose-spec)\n* [PyYAML](https://github.com/yaml/pyyaml)\n* [mergedeep](https://github.com/clarketm/mergedeep)\n* [Understanding multiple Compose files](https://docs.docker.com/compose/extends/#multiple-compose-files)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Parse Compose Specification data using Pydantic",
"version": "0.2.1",
"project_urls": {
"Homepage": "https://github.com/alexmon/compose-pydantic"
},
"split_keywords": [
"compose",
" pydantic"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e2ae029fc8f7e24103556656199ff4993872270c60e6d0d7c396d738561ab2e9",
"md5": "2912b37b4fe42a35c95e826442c2cc04",
"sha256": "58797f622e897335a717547e95dd7a2e415cc6430b432b553d2672240b0f8934"
},
"downloads": -1,
"filename": "compose_pydantic-0.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2912b37b4fe42a35c95e826442c2cc04",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 8371,
"upload_time": "2024-04-28T15:28:48",
"upload_time_iso_8601": "2024-04-28T15:28:48.965759Z",
"url": "https://files.pythonhosted.org/packages/e2/ae/029fc8f7e24103556656199ff4993872270c60e6d0d7c396d738561ab2e9/compose_pydantic-0.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "711dd8e6f5984dfb0e863fa5a17d8a408b5c6292a952c7f718bfb9f622fab3b3",
"md5": "90c49025eaf56faa31175d00305d39c4",
"sha256": "1134c6e21a6b212739dfb2fdf6440e11fb08c7aa55826ca3cd48dc7bf52ef67f"
},
"downloads": -1,
"filename": "compose_pydantic-0.2.1.tar.gz",
"has_sig": false,
"md5_digest": "90c49025eaf56faa31175d00305d39c4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 9718,
"upload_time": "2024-04-28T15:28:51",
"upload_time_iso_8601": "2024-04-28T15:28:51.073523Z",
"url": "https://files.pythonhosted.org/packages/71/1d/d8e6f5984dfb0e863fa5a17d8a408b5c6292a952c7f718bfb9f622fab3b3/compose_pydantic-0.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-28 15:28:51",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "alexmon",
"github_project": "compose-pydantic",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"tox": true,
"lcname": "compose-pydantic"
}