Skip to main content

Graph-based provisioning framework.

Project description

Introduction

Statey is an infrastructure-as-code framework written in Python. The API is designed to be as expressive and Pythonic as possible, and the simplicity of the design makes it just as easy to embed in a Python application as it is to use the command line interface like any infra-as-code application.

Statey supports pulumi resource providers through pylumi, which actually in turn supports Terraform resource providers. This means an entire package index of potential resources is available*.

_NOTE_: Terraform resource providers communicate their type information via JSONSchema, which supports higher-level type operations such as oneOf. At the moment statey does not support anything except basic JSONSchema types (objects, strings, numbers, arrays, booleans, etc.)

The core engine is lightweight and has just a few pure-python dependencies, and it is built from the ground up for extensibility. One of the core data strucrues in statey is the Registry, which is built on top of the excellent plugin engine pluggy. Nearly all of the core functions of statey are hook-based and can be extended or overridden very easily.

Installation

statey and all of its core extension modules can be installed using the following terminal command:

$ pip install statey[all]

_NOTE_: If you are using Zshell you will have to put statey[all] in quotes i.e. “statey[all]”.

To install only the core statey engine the command is:

$ pip install statey

There are a number of possible extras to install, depending on the use-case:

  • fmt - This enables the st.f(‘{some_ref.abc} and other things’) format-string function.

  • pickle - This adds extra pickle extension packages so that functions can be more reliably pickled.

  • cli - This include requirements required to run the statey CLI.

  • pulumi - This includes requirements to utilize pulumi resourc providers.

  • all - This includes requirements from all of the above.

  • core - This includes the requirements from the fmt and cli extras.

  • tests - This includes requirements to run the tests.

  • dev - This includes miscellaneous requirements required for development such as black.

For most users, installing statey[all] will be the proper entry point.

Usage Example

NOTE: to run this example you must have the pulumi aws provider installed. This can be done by running the following if it is not already installed:

$ statey install pulumi/aws==2.13.1

A typical statey module might look something like the following (in a file called statey_module.py):

import statey as st
from statey.ext.pulumi.providers import aws

@st.declarative
def module(session):
        bucket = aws.s3.Bucket(
                bucket='my-bucket-name'
        )
        object_1 = aws.s3.BucketObject(
                bucket=bucket.bucket,
                key='file-1.json',
                source='./static/file1.json',
                contentType='application/json'
        )
        object_2 = aws.s3.BucketObject(
                bucket=bucket.bucket,
                key='file-2.txt',
                content=st.f('This is in a bucket named {bucket.bucket}')
        )

Next, simply run the following in the same directory as your statey_module.py file:

$ export AWS_DEFAULT_REGION=<my_default_region>
$ statey up

The export AWS_DEFAULT_REGION command is essential because setting the region is required for the Pulumi AWS provider. As an alternative and more general solution to statey configuration one could create a statey_conf.py file in the same directory with the following content:

import statey as st

st.helpers.set_provider_defaults("pulumi/aws", {"region": "<my_default_region>"})

The conf file will always be run before the statey_module.py module is loaded, and it is intended to register hooks to change statey’s behavior.

After running statey up, the application will display a confirmation message, and if confirmed will subsequently execute the operations displayed in the plan. At this point the statey application is fully aware of and managing the infrastructure defined in statey_module.py. You can edit, remove, add to or delete this infrastructure fluently and incrementally without interrupting your existing resources. For example, perhaps we want to change the naming scheme for our s3 objects:

import statey as st
from statey.ext.pulumi.providers import aws

@st.declarative
def module(session):
        bucket = aws.s3.Bucket(
                bucket='my-bucket-name'
        )
        object_1 = aws.s3.BucketObject(
                bucket=bucket.bucket,
                key='statey-test-file-1.json',
                source='./static/file1.json',
                contentType='application/json'
        )
        object_2 = aws.s3.BucketObject(
                bucket=bucket.bucket,
                key='statey-test-file-2.txt',
                content=st.f('This is in a bucket named {bucket.bucket}')
        )

You should get an output something like the following:

* object_2:current:task:delete
| * object_1:current:task:delete
* | object_2:config:task:create
 /
* object_1:config:task:create

Since you are changing the key of each object, statey detects that each one needs to be deleted and recreated, and understands the order those things need to be done in. The same goes for any update you make to your configuration, or tearing down all of your infrastructure altogether.

Compatibility

Tests are passing on Mac OS X and Ubuntu, see recent test runs in Actions for details.

Right now statey is only tested with Python 3.8. There are known imcompatabilities with Python 3.6, and they should be addressed. Python 3.7 has not been tested but may very well work as intended.

Contact

If you have issues using this repository please open a issue or reach out to me at cameron.l.feenstra@gmail.com.

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

statey-0.0.5.tar.gz (102.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

statey-0.0.5-py3-none-any.whl (125.1 kB view details)

Uploaded Python 3

File details

Details for the file statey-0.0.5.tar.gz.

File metadata

  • Download URL: statey-0.0.5.tar.gz
  • Upload date:
  • Size: 102.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.7

File hashes

Hashes for statey-0.0.5.tar.gz
Algorithm Hash digest
SHA256 efd6ae6e3353673e711b6e8380d68779ffec538fde4ebe25f91c9e12ee7f0639
MD5 d8244bbbc6003e584df928af086cb511
BLAKE2b-256 21835cfe081af316202002b283b11dec1452f9ad3d64e2163db3ff73648a220e

See more details on using hashes here.

File details

Details for the file statey-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: statey-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 125.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.54.0 CPython/3.7.7

File hashes

Hashes for statey-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 95761dc399f09dc1cfbe3038d578b3b5f2f7d9e3760c11532ab27ab89297a527
MD5 d9f7b8d7bde4811621d6d0ac6b4d4d5b
BLAKE2b-256 f9f7d53c9824f0c0afd7308839afffcb6a67df824c8fa7b177ccfb14202ef2f3

See more details on using hashes here.

Supported by

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