Skip to content

Type-Safe Development

idfkit ships auto-generated type stubs for all 858 EnergyPlus object types. Your IDE gets autocomplete, inline documentation, and error detection out of the box — no plugins or configuration needed.

Differs in Python

Static types generated from the schema exists in both libraries and does not behave the same way in Python. The ledger records it as Python partial, JavaScript complete, and what differs is stated here rather than left to be discovered.

Coverage differs, and the difference is visible to anyone not on the newest release. The Python stub set is generated for one EnergyPlus version at a time and is currently shipped for 26.1.0 only, so a model loaded at 9.4 gets the 26.1 field names and choice lists from the editor. The TypeScript type maps are emitted per version and selected by the caller, who parameterises the document with the map for the version being read, so an older model is typed as that older model or is left untyped rather than mistyped.

Application differs too. Python's stubs apply implicitly to every document. TypeScript's are opt-in by construction: an unparameterised document stays untyped, which is what version-generic code needs.

The full entry, including the vocabulary this capability owns, is on the capability parity page.

IDE Autocomplete and Inline Docs

Every object type has a typed attribute accessor on the document and typed fields on individual objects. Your IDE will show field names, types (including Literal for enumerated choices), docstrings with units, defaults, and valid ranges.

Accessors are plural (doc.zones, doc.materials), except for the types a model holds at most one of, which are singular (doc.building, doc.output_sqlite). The plural spelling of those is deprecated. A misspelled accessor, such as doc.zonez, is a type error.

from idfkit import load_idf
from idfkit.versioned import IDFDocumentV24_1

# A file's release is only known once it is read, so the model is typed
# AnyIDFDocument: what every supported release has in common.
model = load_idf("building.idf")
zones = model.zones  # IDFCollection[AnyZone]

# Name the release to type the model as that release declares its objects.
model = load_idf("building.idf", as_type=IDFDocumentV24_1)
zones = model.zones  # IDFCollection[Zone]

# O(1) lookup by name returns the typed object
zone = zones["Office"]

# Field access with IDE autocomplete and type info
print(zone.x_origin)  # float | None
print(zone.multiplier)  # float | int | None

# Subscript access also works
all_zones = model["Zone"]

For example, hovering over zone.ceiling_height in your IDE will show:

(property) ceiling_height: float | Literal["Autocalculate"] | None

A field is cleared with None, not with an empty string.

Typed for a Release

A file's EnergyPlus release is only known once the file is read, so load_idf() and load_epjson() return an AnyIDFDocument. Its objects declare the fields every supported release shares, and its collections hold types such as AnyZone and AnyLights. A field only some releases have is a type error on them; its message names the fix, _NotAFieldInEveryRelease_TypoOrNarrowWithAsVersion.

State the release to type the model as that release declares it. Each release has a document type in idfkit.versioned, from IDFDocumentV8_9 to IDFDocumentV26_2, which is IDFDocument:

from idfkit import load_idf, new_document
from idfkit.versioned import IDFDocumentV9_4, IDFDocumentV23_2, as_version

# Create a model typed for one release
legacy = new_document(IDFDocumentV9_4)

# Load a file that must be one release, or any release in a range
model = load_idf("building.idf", as_type=IDFDocumentV23_2)
recent = load_idf("building.idf", since="22.1")

# Narrow a document you already hold; raises TypeError if it is another release
typed = as_version(doc, IDFDocumentV23_2)
lights = typed["Lights"]["Office Lights"]
print(lights.watts_per_zone_floor_area)  # declared in 23.2, renamed in 24.1
  • new_document(IDFDocumentV9_4) creates a model typed for that release. new_document() and new_document(version=(25, 2, 0)) are typed as IDFDocument, the latest release, whatever version they create.
  • as_type= on a loader, or as_version(doc, ...) on a document you hold, names one release or a tuple of them. since= and before= name a range. The release is checked at run time, and a mismatch raises TypeError.
  • On a release-typed document, an object type or field that release lacks is a type error, so code written for 23.2 cannot reach a 24.1 field by accident.

Strict Field Access

By default, accessing a misspelled field name raises an InvalidFieldError. Strict mode also checks each value you assign, through attribute assignment or update(), against the schema, as add() does: a wrong type, a choice the field does not list, or a number out of range raises ValidationFailedError. Disable strict mode to return None for unknown fields and store such values as given:

from idfkit import new_document

# Strict field access is on by default
doc = new_document()

zone = doc.zones.add("Office")
zone.x_origin = 0.0  # OK: a valid field and a valid value

# zone.x_orgin = 0.0    # InvalidFieldError: typo caught immediately
# zone.multiplier = 0   # ValidationFailedError: below the minimum of 1

# Also the default when loading files
# model = load_idf("building.idf")
# model = load_epjson("building.epJSON")
Function Parameter
new_document() strict=True (default)
load_idf() strict=True (default)
load_epjson() strict=True (default)

Some checks hold in either mode. NaN and infinity are refused, because neither EnergyPlus nor epJSON can hold them. update() refuses a field name the type does not have.

Tip

Strict mode is on by default. Disable it with strict=False when loading third-party IDF files that may contain non-standard fields or values.

Required fields are typed without None: material.thickness is a float. Reading one the model leaves unset raises MissingRequiredFieldError. Test it with material.get("thickness"), which returns None instead.

Undeclared Names Are Type Errors

Strict mode catches a misspelled field when the code runs. On a typed object, a type checker catches it before, whatever strict is set to. A typed object is one taken from doc["Zone"] or doc.zones, along with its extensible groups, such as surface.vertices[0]. Its class declares the schema's snake_case field names and nothing else:

zone = doc["Zone"]["Office"]
zone.x_orgin = 0.0       # reported: not a field of Zone
print(zone.celing_height)  # reported

The same holds for an eppy-style capitalised name such as zone.X_Origin, which works at run time. Use the snake_case name, or item access, zone["X_Origin"]. A field that exists only in some releases, such as Lights.watts_per_zone_floor_area up to 23.2, is reached by typing the document for its release, as in Typed for a Release.

Objects from doc.add(), doc.get_collection() and the eppy API (doc.idfobjects[...], newidfobject(), getobject()) are plain IDFObject and accept any attribute name, so a typo on them is caught only at run time.

Typed Creation

Create objects through their collection to have the fields checked as you write them:

zone = doc.zones.add("Office", ceiling_height=2.7, multiplier=1)  # returns Zone
wall = doc["BuildingSurface:Detailed"].add("Wall 1", surface_type="Wall", ...)

collection.add(name, **fields) takes the type's fields as keyword arguments, so a misspelled or missing required field is a type error, and it returns the typed object. It validates the values as doc.add() does; pass validate=False to skip that. doc.add("Zone", ...) still works, but takes any keyword and returns a plain IDFObject.

Passing an existing object to collection.add(obj) is deprecated; use doc.addidfobject(obj).

Dynamic Key Access

When the object type is a string literal, doc["Zone"] returns a fully typed collection. When the key comes from a variable, use get_collection() to get a safely typed IDFCollection[IDFObject]:

# Literal key — fully typed, IDE knows the return type
zones = model["Zone"]

# Dynamic key — use get_collection() for variable object types
obj_type = "Zone"
collection = model.get_collection(obj_type)  # IDFCollection[IDFObject]

Use doc["Zone"] when you know the type at write time. Use doc.get_collection(obj_type) in generic functions that accept any object type.

Why get_collection()?

doc["Zone"] is typed by one __getitem__ overload per object type, each keyed on a string literal. A plain str variable matches none of them, so it does not type-check. get_collection() is the escape hatch: it accepts any str and returns the base IDFCollection[IDFObject] type. To iterate over every collection in a document, use doc.collections.

Version Availability

Type stubs include "Since: X.Y.Z" annotations in docstrings for object types and fields that were introduced after EnergyPlus 8.9.0. This helps you avoid using features that don't exist in your target version:

from idfkit import new_document
from idfkit.versioned import IDFDocumentV25_2

doc = new_document(IDFDocumentV25_2)

# SpaceHVAC:ZoneReturnMixer was added in EnergyPlus 24.2.0
# IDE docstring shows: "Since: 24.2.0"
mixer = doc["SpaceHVAC:ZoneReturnMixer"].add(
    "Return Mixer 1",
    zone_name="Office",
    zone_return_air_node_name="Office Return Node",
)

Hovering over SpaceHVACZoneReturnMixer in your IDE shows the docstring including "Since: 24.2.0". On a document typed for an earlier release, such as IDFDocumentV23_2, doc["SpaceHVAC:ZoneReturnMixer"] is a type error.

See Also