Preprocessor Variable Extraction
This page explains the specific part of netherframe naming that moves from
runtime into import time when you use nf_autoid.
For the main contract, see Preprocessor Guide. For the practical workflow, see Custom Codec And Autoscope.
What This Page Is About
The preprocessor does not make netherframe "automatic" in a broad sense. It
does one narrow thing: it turns a small set of supported source patterns into
explicit nf_id arguments during import.
Today that means:
Bind-annotated assignmentswith ... as namebindings whenBindContextis present
Import-Time Naming Vs Runtime Naming
Without the codec, netherframe can still infer ids in some situations at runtime by inspecting execution context.
With the codec:
- supported names are injected during import
- the supported behavior is explicit and easier to reason about
- those call sites do not rely on runtime frame inspection
That is the main distinction. The codec is a predictable import-time contract, not a replacement for every other naming path in the framework.
Extraction Points
Assignment Extraction
#!/usr/bin/env python3
# coding: nf_autoid
from nf.core import App, Bind, BindContext, Stack
from nf.providers.hashicorp.aws import AwsProvider, Vpc
with App() as app, Stack() as stack, BindContext:
with AwsProvider(region="us-east-1") as aws, BindContext:
vpc: Bind = Vpc(cidr_block="10.0.0.0/16")
The assigned name becomes the injected nf_id.
with Binding Extraction
# coding: nf_autoid
from nf.core import App, BindContext, Stack
with App() as app, Stack() as stack, BindContext:
...
The bound name becomes the injected nf_id.
Multiple Files
Each file that relies on codec rewriting needs its own # coding: nf_autoid
declaration. The codec is enabled per module, not per package.
infrastructure/network.py
# coding: nf_autoid
from nf.core import App, Bind, Stack, autoscope
from nf.providers.hashicorp.aws import Vpc
@autoscope
class Network(Stack):
def __init__(self, *, nf_scope: App, nf_id: str) -> None:
super().__init__(nf_scope=nf_scope, nf_id=nf_id)
self.vpc: Bind = Vpc(cidr_block="10.0.0.0/16")
app.py
# coding: nf_autoid
from nf.core import App, Bind, BindContext
from infrastructure.network import Network
with App() as app, BindContext:
network: Bind = Network()
When Import-Time Extraction Is Not The Right Tool
Keep explicit nf_id when:
- ids come from a loop index or config value
- the name should not depend on the Python variable name
- you are creating resources through helper flows the codec does not rewrite
- the stable external name matters more than local source ergonomics
That is not a failure of the codec. It is the boundary of the feature.
Registration
The codec must be registered before Python imports a module that declares
# coding: nf_autoid.
The nf CLI handles this automatically.
If you run modules directly, register the codec first:
from nf.codec.autoid import register_codec
register_codec()
Performance Framing
The main benefit is predictability first and reduced runtime name detection second. Import-time transformation usually costs a small one-time parse and rewrite per module import.
If you need the older benchmarking discussion, see Preprocessor Performance Analysis, but treat it as background rather than the primary contract doc.