Skip to main content

A module for working with Cloud Native Application Bundles in Python

Project description

Python CNAB Library

Work-in-progress library for working with CNAB in Python.

There are probably three main areas of interest for a CNAB client:

  1. Creation/parsing of the bundle.json format
  2. Building invocation images
  3. Running actions against a CNAB

At this early stage only the first of these is currently work-in-progress.

Parsing bundle.json

Nothing too fancy here, the Bundle class has a from_dict static method which builds a full Bundle object.

import json
from cnab import Bundle

with open("bundle.json") as f:
    data = json.load(f)

bundle = Bundle.from_dict(data)

This could for example be used for validation purposes, or for building user interfaces for bundle.json files.

Describing bundle.json in Python

You can also describe the bundle.json file in Python. This will correctly validate the structure based on the current specification and would allow for building a custom DSL or other user interface for generating bundle.json files.

import json
from cnab import Bundle, InvocationImage

bundle = Bundle(
    name="hello",
    version="0.1.0",
    invocation_images=[
        InvocationImage(
            image_type="docker",
            image="technosophos/helloworld:0.1.0",
            digest="sha256:aaaaaaa...",
        )
    ],
)

print(json.dumps(bundle.to_dict(), indent=4))

Thanks

Thanks to QuickType for bootstrapping the creation of the Python code for manipulating bundle.json based on the current JSON Schema.

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

cnab-0.1.1.tar.gz (4.7 kB view hashes)

Uploaded source

Built Distribution

cnab-0.1.1-py3-none-any.whl (18.8 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page