Skip to main content

Opslib

Discord

Opslib is a Python infrastructure-as-code framework which offers powerful abstractions to make deployment straightforward and fun.

Installing

$ pip install -U pyopslib

A Simple Example

# stack.py
from opslib import SshHost, Stack
from opslib.ansible import AnsibleAction
from opslib.terraform import TerraformProvider

stack = Stack(__name__)

stack.hetzner = TerraformProvider(
    name="hcloud",
    source="hetznercloud/hcloud",
    version="~> 1.38.2",
)

stack.server = stack.hetzner.resource(
    type="hcloud_server",
    args=dict(
        name="opslib-example",
        server_type="cx11",
        image="debian-11",
        location="hel1",
        ssh_keys=["my-key"],
    ),
    output=["ipv4_address"],
)

stack.vm = SshHost(
    hostname=stack.server.output["ipv4_address"],
    username="root",
)

stack.install_docker = AnsibleAction(
    host=stack.vm,
    module="ansible.builtin.shell",
    args=dict(
        cmd="curl -s https://get.docker.com | bash",
        creates="/opt/bin/docker",
    ),
)

Deploy the stack. It's called - because it's the top level Stack object:

export HCLOUD_TOKEN="..."  # https://docs.hetzner.com/cloud/api/getting-started/generating-api-token
opslib - deploy

Now we can interact with the VPS host, which we named vm above:

opslib vm run 'set -x; whoami; uptime'
opslib vm run docker run --rm hello-world

Finally, we tear down the stack:

opslib - destroy

Features

Opslib does its best to enable readable code so you can reason about your stack. This means making use of descriptors, typing and other Python language features where it makes sense.

  • Defining components
  • Batteries included
    • Terraform: invoke any provider from the Terraform Registry.
    • Ansible: invoke any module from Ansible Collections.
    • Places: native modeling of local/remote hosts, files, directories and shell commands.
    • A handful of specific integrations (e.g. systemd, restic). I plan to spin them off into a library of reusable components.
  • Operations model
    • Most actions boil down to invoking subprocess commands or HTTP requests. All actions return Results, which are understood by the reporting layer.
    • Many components, after being successfully deployed, are skipped on subsequent deployments, unless their props change, or are manually refreshed to account for remote state changes.
    • Commands may track deployment of other components (e.g. configuration files) and only get re-run when needed.
    • Lazy variables, that wrap values which are available after another component is deployed, get evaluated when they are needed.

Links

Metadata

Release files for pyopslib 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyopslib 0.2
File Size Uploaded Provenance
pyopslib-0.2.tar.gz 179.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pyopslib 0.2
File Interpreter ABI Platform
pyopslib-0.2-py3-none-any.whl Python 3 none any Details

Total release size: 209.1 kB

Release files / pyopslib-0.2.tar.gz

Download URL pyopslib-0.2.tar.gz
Size 179.5 kB
Tags Source
SHA-256 checksum
How to use checksums
826f1bc5afbcf3346a5256c14186be81090f559e651082ea135f509c9d0dbf8b
BLAKE2b-256 checksum
How to use checksums
86612638f0c503ec53f9c7157e9b7b0ab819be59a1924aef4a0681a52f74171d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.31.0

Release files / pyopslib-0.2-py3-none-any.whl

Download URL pyopslib-0.2-py3-none-any.whl
Size 29.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ebe8e600a2083664daa26a0eccddcb8c92fe9aa9a6fa5f82fd4a57e37f845427
BLAKE2b-256 checksum
How to use checksums
ca912da2b2b9e03fea200802a511534e4a581c3a0d1fc072b17cf2a65d4c1647
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.31.0

Security for pyopslib 0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page