Metadata-Version: 2.5
Name: slopifc
Version: 0.2.1
Summary: Python ctypes binding for slopifc: IFC parsing and geometry
Project-URL: Homepage, https://github.com/aectooling/slopifc
Project-URL: Documentation, https://github.com/aectooling/slopifc/blob/main/docs/python.md
Project-URL: Repository, https://github.com/aectooling/slopifc
Project-URL: Issues, https://github.com/aectooling/slopifc/issues
Author: slopifc contributors
License-Expression: MIT
Keywords: bim,ifc,parser,zig
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.10
Provides-Extra: dev
Requires-Dist: numpy>=1.24; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Provides-Extra: numpy
Requires-Dist: numpy>=1.24; extra == 'numpy'
Description-Content-Type: text/markdown

# `slopifc` (Python)

Python ctypes binding for [slopifc](../../README.md): IFC parsing and geometry
over the Zig-exported C ABI. Parsing has no required Python dependencies;
geometry uses optional NumPy.

> **Status: alpha.** Parsing, entity queries, and geometry preparation packaged
> with a native library for each supported platform.

## Contract

Entities are views into the owning `File` and must not outlive it. Parser queries
serialize with `File.close()`: an in-flight query finishes before its native
file storage is released. Type queries
include IFC2X3, IFC4, or IFC4X3 ADD2 subtypes by default. Structured attributes
return native Python values, including immutable `TypedValue` wrappers and
`BinaryValue(data: bytes, bit_length: int)`. Binary data is copied and remains
valid after the file closes. The parser C ABI is private to the wheel and may change
between releases. Geometry has a separate versioned native descriptor contract. See
[`docs/python.md`](../../docs/python.md).

## Development

```bash
# from repository root
zig build python -Doptimize=ReleaseFast
pip install -e "./packages/python[dev]"
python -c "import slopifc; print(slopifc.__version__)"
pytest packages/python/tests
scripts/check-python-abi-symbols
```

Without pip, point `PYTHONPATH` at the src tree:

```bash
zig build python
PYTHONPATH=./packages/python/src python3 -c "import slopifc; print(slopifc.__version__)"
```

`zig build python` is Zig-only: it writes the native library into `zig-out/`
and copies the platform-specific file next to
`src/slopifc/__init__.py`. A wheel build invokes Zig through the Hatch build
hook and includes one `.so`, `.dylib`, or `.dll`.

## Layout

| Path | Contents |
| --- | --- |
| `src/slopifc/__init__.py` | public ctypes API |
| `src/slopifc/_slopifc_core.*` | native library (gitignored; from `zig build python`) |
| `tests/` | unit tests |
| `pyproject.toml` | installable package metadata (hatchling) |

## Geometry

Install `slopifc[numpy]` to enable geometry preparation:

```python
import slopifc

with slopifc.open("model.ifc") as model:
    geometry = model.prepare_geometry()

if len(geometry.instances):
    mesh = geometry.instance_mesh(0)
    print(mesh.vertices.shape, mesh.triangles.shape)
```

The owned arrays include shared meshes, instances, materials, IFC IDs, and
transforms in metres. They remain valid after the model closes. See the
[geometry API](../../docs/python.md#geometry) and the
[runnable OBJ/MTL and PNG example](../../examples/python/README.md#geometry-example).
Parsing has no required Python dependencies; geometry requires NumPy.

For physical curve sampling, pass
`slopifc.GeometryOptions(curve_quality=slopifc.CurveQuality(0.001))` to full or
batch preparation. The chord error is in metres; optional `max_angle_radians`
and `max_segments` default to 0.1 and 4096. Caps fail instead of weakening the
requested sampling. This controls curve samples, not final-mesh distance after
cleanup and float32 conversion. Omit quality to keep legacy sampling. See the
[shared quality contract](../../docs/native-geometry.md#optional-curve-sampling-in-the-zig-core).

`model.iter_geometry(batches=slopifc.GeometryBatchOptions(...))` prepares owned
snapshots in batches with explicit native byte budgets. Use the iterator as a
context manager and consume each batch before requesting the next. See
[batch ownership, cancellation and memory accounting](../../docs/geometry-batches.md#native-and-python-adapters).

`model.query_semantics([42], include_type=True)` returns owned property, quantity,
material and unit data with explicit provenance. IDs and integer values remain
decimal strings. Empty IDs select none; no effective-value merge or unit
conversion is applied. See the [shared semantic contract](../../docs/semantic-queries.md).
