Skip to content
BIMpedia

Reading IFC with code (IfcOpenShell, web-ifc)

Opening IFC files with open-source libraries to count, check, extract and report, without any authoring software, and what a first script looks like.
Updated 6 November 2026

IFC files can be read and written by code using open-source libraries, independently of any authoring tool. IfcOpenShell (Python and C++) and web-ifc (JavaScript and WebAssembly, the one BIMpedia's IFC tools use in your browser) are the best known. With a few lines you can count elements, list properties, check rules or export data, on files from any software that exports IFC.

At a glance

LibraryLanguageRunsKnown for
IfcOpenShellPython (and C++)Desktop, servers, notebooks; the base of Bonsai (formerly BlenderBIM)Full IFC read and write, geometry, IDS checks, utilities
web-ifcJavaScript / WebAssemblyBrowsers and Node.jsFast parsing in the browser; used by That Open Company's tools
xBIM.NET (C#)Desktop and serversIFC for .NET applications
IfcOpenShell utilitiesPythonCommand lineConverting, validating, diffing files

How IFC data is organised (the minimum you need)

  • Entities are the things: IfcWall, IfcDoor, IfcSpace, IfcBuildingStorey.
  • Property sets hold properties: Pset_DoorCommon.FireRating, Pset_WallCommon.IsExternal.
  • Quantity sets hold quantities: Qto_WallBaseQuantities.NetSideArea.
  • Relationships connect them: which storey contains the wall, which type the door is, which space a component is in.
  • Every object has a GlobalId that stays the same between exports (if the authoring tool behaves).

A first script

The task: list every door with its storey and fire rating, and flag doors with no rating. In Python with IfcOpenShell, the logic is:

import ifcopenshell
import ifcopenshell.util.element as el

model = ifcopenshell.open("model.ifc")
for door in model.by_type("IfcDoor"):
    psets = el.get_psets(door)
    rating = psets.get("Pset_DoorCommon", {}).get("FireRating")
    storey = el.get_container(door)
    print(door.GlobalId, storey.Name if storey else "-", door.Name, rating or "MISSING")

Eight lines replace an hour of opening the model and filtering schedules, and they work on any IFC from any tool.

Worked example

A client receives IFC models from five consultants each month. A Python script runs on every delivery: it counts elements by type and storey, lists doors and walls with no fire rating, finds proxy elements (IfcBuildingElementProxy), and writes a one-page report per model. The information manager reads five pages instead of opening five models, and sends each consultant a list they can act on.

Common mistakes

  • Expecting every exporter to fill the standard property sets: many put properties in custom sets.
  • Comparing GlobalIds between exports from tools that regenerate them.
  • Loading geometry when the task only needs properties (much slower).
  • Forgetting units: lengths may be in millimetres or metres depending on the file.

Where to read more

The IfcOpenShell documentation and community (including the OSArch forum) cover installation and examples. buildingSMART documents the IFC schema, property sets and quantity sets. That Open Company documents web-ifc.