Skip to main content

Parse Compose Specification data using Pydantic

Project description

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.

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

pip install compose-pydantic

Usage

Read multiple compose files

from compose_pydantic import ComposeSpecificationFactory

csf = ComposeSpecificationFactory()
compose = csf(['tests/compose/docker-compose.yml', 'tests/compose/docker-compose.override.yml'])

print(compose.__dict__)

Result:

{'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}

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.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.

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-pydantic-0.1.2.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

compose_pydantic-0.1.2-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file compose-pydantic-0.1.2.tar.gz.

File metadata

  • Download URL: compose-pydantic-0.1.2.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for compose-pydantic-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e08fbe4aa5b030b34b90ec2cd4295df102781b206577a43e91815597e68c658b
MD5 70b7fdffb6aabfcb2a014ec1ac703c09
BLAKE2b-256 c7d820ea639ad1e566aee1398ba1fe832791071ffd67743fa3f21d226efbed66

See more details on using hashes here.

File details

Details for the file compose_pydantic-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: compose_pydantic-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for compose_pydantic-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0f730a48f634a2cf009668cbf5aba45a9f0d1d34515e5114de85f0a40f166f7a
MD5 230a9ff3f85a337bd1d4013a3edfed54
BLAKE2b-256 83267f7ca6f9509b92b8a9c962f88ba89cc3d02116febac4281ec87ef0e6e6e3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page