Metadata-Version: 2.4
Name: obplib
Version: 3.1.0
Summary: A library for the creation of beam paths
Author-email: Freemelt AB <opensource@freemelt.com>
License-Expression: Apache-2.0
Project-URL: Homepage, https://gitlab.com/freemelt/openmelt/obplib-python
Project-URL: Download, https://gitlab.com/freemelt/openmelt/obplib-python/-/archive/3.1.0/obplib-python-3.1.0.tar.gz
Keywords: obp,openbeampath,freemelt
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.13
Description-Content-Type: text/markdown
License-File: LICENSES/Apache-2.0.txt
Requires-Dist: click
Requires-Dist: protobuf<8,>=4.21.12
Requires-Dist: protobuf<8,>=6.33.0; python_version >= "3.14"
Requires-Dist: numpy
Requires-Dist: matplotlib
Requires-Dist: ipywidgets
Provides-Extra: test
Requires-Dist: coverage; extra == "test"
Requires-Dist: nose2; extra == "test"
Dynamic: license-file

<!--
SPDX-FileCopyrightText: 2019,2020,2026 Freemelt AB

SPDX-License-Identifier: Apache-2.0
-->

# OBPlib for Python

OBPlib creates and reads OpenBeamPath (OBP) data for electron-beam powder-bed
fusion systems. Build a path from lines, cubic Bézier curves, timed points, and
synchronization signals, then write it as binary `.obp` or human-readable
`.obpj` data.

The package requires Python 3.13 or newer.

## Install

A plain wheel installation includes NumPy, Matplotlib, and ipywidgets along
with the core dependencies; no viewer or notebook extras are needed. The desktop
viewer also needs Tcl/Tk support in your Python installation.

On a Debian system configured with the Freemelt package repository:

```console
$ sudo apt-get update
$ sudo apt-get install python3-obplib
```

To work from a source checkout on Debian 13 (Trixie), install the build and
runtime dependencies from Debian, then make an editable installation in a
virtual environment:

```console
$ sudo apt-get install python3-click python3-protobuf \
    python3-grpc-tools protobuf-compiler python3-setuptools python3-wheel \
    python3-venv
$ python3 -m venv --system-site-packages .venv
$ .venv/bin/python -m pip install --no-build-isolation --no-deps --editable .
```

The editable-install step also generates the Python modules for `OBP.proto`.

## Quick start

Coordinates and spot sizes are in micrometres (µm), beam power is in watts,
and scan speed is in micrometres per second (µm/s).

```python
from pathlib import Path

import obplib as obp

beam = obp.Beamparameters(spot_size=80, power=250)

path = [
    obp.Line(
        obp.Point(0, 0),
        obp.Point(10_000, 0),
        500_000,
        beam,
    ),
    obp.Curve(
        obp.Point(10_000, 0),
        obp.Point(12_000, 0),
        obp.Point(15_000, 3_000),
        obp.Point(15_000, 5_000),
        400_000,
        beam,
    ),
]

obp.write_obp(path, Path("example.obp"))
obp.write_obpj(path, Path("example.obpj"))
```

`example.obp` is the length-delimited protobuf representation used by OBP
consumers. `example.obpj` is a JSON representation intended for inspection and
conversion.

Read binary data back into library objects:

```python
segments = obp.read_obp("example.obp")

for segment in segments:
    print(type(segment).__name__, segment)
```

Reading `.obpj` is deliberately different: `read_obpj()` returns the decoded
JSON dictionary rather than path objects.

```python
document = obp.read_obpj("example.obpj")
print(document["OBP"][0]["line"])
```

## Documentation and examples

- [User guide](docs/user-guide.md) — concepts, every public path type,
  transformations, file I/O, command-line tools, viewers, and current
  limitations.
- [Create an OBP job](examples/create_job.py) — builds a mixed path and writes
  both file formats.
- [Transform a path](examples/transform_path.py) — scales, rotates, and
  translates geometry without modifying the originals.

Run an example after installing the package:

```console
$ python3 examples/create_job.py --output-dir /tmp/obp-example
```

## Command-line tools

Convert between binary and textual OBP:

```console
$ obpc decompile example.obp   # writes example.obpj
$ obpc compile example.obpj    # writes example.obp
```

Install the viewer dependencies and inspect a binary path:

```console
$ sudo apt-get install python3-matplotlib python3-numpy python3-tk
$ obpviewer example.obp
```

See the [user guide](docs/user-guide.md#command-line-tools) for compiler usage,
viewer controls and cross-platform wheel installation. SVG conversion is no
longer included.
See [release validation](docs/release-validation.md) for dependency and GUI qualification.

## Format definition

The protocol is defined in [`openbeampath/OBP.proto`](openbeampath/OBP.proto).
Each protobuf `Packet` is stored with a varint32 length prefix in an `.obp`
file. An `.obpj` file contains the JSON form under a top-level `"OBP"` array.

## License

Copyright © 2018–2026 Freemelt AB.

OBPlib and OpenBeamPath are licensed under the
[Apache License 2.0](LICENSES/Apache-2.0.txt).
