Skip to content

Building Your First Application

Build a hybrid app with separate network and storage stacks, typed AWS bindings and outputs. Netherframe plans the whole app and stores state locally for this example. Set up Python 3.15 or later and the CLI first. See installation.

Project Layout

my-web-app/
  app.py
  pyproject.toml

pyproject.toml

Add the settings to your project’s pyproject.toml.

[tool.nf]
apps = ["app:app"]

Install The AWS Binding Package

For a source checkout, see AWS binding installation.

uv add netherframe.providers.hashicorp.aws
pip install netherframe.providers.hashicorp.aws

app.py

# coding: nf_autoid

from nf.core import App, Bind, BindContext, Output, Stack, autoscope
from nf.providers.hashicorp.aws import AwsProvider, S3Bucket, Subnet, Vpc


@autoscope
class NetworkStack(Stack):
    def __init__(self, *, nf_scope: App | None = None, nf_id: str | None = None, region: str) -> None:
        super().__init__(nf_scope=nf_scope, nf_id=nf_id)

        aws: Bind = AwsProvider(region=region)

        self.vpc: Bind[Vpc] = Vpc(
            cidr_block="10.0.0.0/16",
            enable_dns_support=True,
            enable_dns_hostnames=True,
            tags={"Name": "docs-example-vpc"},
        )

        self.public_subnet: Bind[Subnet] = Subnet(
            vpc_id=self.vpc.output.id,
            cidr_block="10.0.1.0/24",
            availability_zone=f"{region}a",
            map_public_ip_on_launch=True,
        )

        vpc_id: Bind = Output(value=self.vpc.output.id)


@autoscope
class StorageStack(Stack):
    def __init__(self, *, nf_scope: App | None = None, nf_id: str | None = None, region: str) -> None:
        super().__init__(nf_scope=nf_scope, nf_id=nf_id)

        aws: Bind = AwsProvider(region=region)

        self.bucket: S3Bucket = S3Bucket(
            nf_id="assets",
            bucket="replace-with-a-globally-unique-name",
            force_destroy=True,
            tags={"Name": "docs-example-assets"},
        )

        bucket_id: Bind = Output(value=self.bucket.output.id)


def app() -> App:
    with App() as app, BindContext:
        network: Bind = NetworkStack(region="us-east-1")
        storage: Bind = StorageStack(region="us-east-1")
    app.enable_hybrid_execution_local(path=".nf.out/hybrid.tfstate")
    return app

The app context makes both stacks children of the app. In each stack constructor, @autoscope makes the stack the parent of its provider, resources and outputs. The bucket keeps nf_id="assets" so it has a stable address even if the Python attribute name changes.

Plan, review and apply

Configure AWS credentials and substitute a globally unique bucket name. Keep the project's Python environment active.

nf plan --app app --out reviewed-plan.json

Review the changes for network and storage in the same plan, then apply it:

nf apply --app app --plan-file reviewed-plan.json
nf plan --app app

The next plan should report no changes. The two stacks share the app’s state backend at .nf.out/hybrid.tfstate. Run nf destroy --app app when you’re done with the example.

Why This Example Uses The AWS Binding Package

The published AWS package gives you:

  • resource-specific Python imports instead of raw Terraform type strings
  • better autocomplete
  • clearer examples for teams reading the code later

Next Steps