Skip to main content

py2aspen

A Python wrapper for Aspen Plus built on comtypes ✨

PyPI version Python Downloads Stars Issues License

comtypes uv ty ruff QQ Group

English | 简体中文

A Python wrapper for Aspen Plus built on comtypes, packaging COM automation calls into an object-oriented Python API: connect to the application, open .bkp files, place/connect blocks and streams on the flowsheet, read/write properties, run simulations, and export reports. It supports local COM as well as remote connections over DCOM.

Installation

Install with uv (recommended) or pip:

uv add py2aspen
# or
pip install py2aspen

Minimal example

from py2aspen import UnitAspen, bind, MaterialStream, MaterialStreamInput

# ProgID for Aspen Plus
PROGID = "AspenPlus.Document"
BKP_PATH = r"C:\path\to\solid1.bkp" # Example file shipped with Aspen; pick a valid path on your machine

with UnitAspen(PROGID) as aspen:
    aspen.suppress_dialogs(True)
    aspen.open_bkp(BKP_PATH)
    aspen.set_visible(True)

    stream = MaterialStream(name="WET-COAL")
    aspen.exec(bind(stream))

    stream.set_input(MaterialStreamInput(temperature=100))
    aspen.engine_run()

The with block automatically calls lazy_bind() to enable late binding and closes Aspen Plus on exit. To keep the application window open after the script finishes (e.g. for debugging), skip with and call lazy_bind() manually instead.

Development workflow (uv + ty + ruff)

The project uses the src layout with uv_build as the build backend. Dependency management is handled by uv, type checking by ty, and code style by ruff.

Generate the comtypes type module

py2aspen depends on comtypes.gen.Happ (the Aspen Plus type library). The repo ships the .tlb at tlb/v14/happ.tlb; after installing, generate it once in the target Python environment (the output is written to <env>/Lib/site-packages/comtypes/gen/):

.venv\Scripts\python.exe -c "import comtypes.client as cc; cc.GetModule(r'tlb\v14\happ.tlb')"

Re-run this command after recreating the virtual environment or deleting the comtypes/gen/ directory.

Environment and dependencies

# Initialize the environment after cloning (installs runtime deps and the dev group from pyproject.toml)
uv sync

Type checking (ty)

uvx ty check            # Check the whole repo
uvx ty check src/       # Check a specific path

Code style (ruff)

uvx ruff check          # Static checks
uvx ruff check --fix    # Auto-fix
uvx ruff format         # Format

Tests

uv run pytest -v        # Or run the pytest task in VS Code

Project Status

Project Status

Contributors

Thanks to everyone who contributes to py2aspen!

Contributors

Special thanks to the friends in our chat group:

QQ: 562721026

TG: None

Thanks to the following similar projects for reference:

AspenPlus-Python-Interface - Python interface which acts as an API to automate the design synthsis. It includes all variables for RADFRAC, DSTWU, Flash2, RYield, RPlug, RCSTR, Heater, Mixer, Splitter. It includes a optimization library implementation from scipy

Contributions of any kind are welcome: open an Issue to report problems or suggest features, or submit a Pull Request to improve the code.

Metadata

Release files for py2aspen 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py2aspen 0.3.0
File Size Uploaded
py2aspen-0.3.0.tar.gz 20.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py2aspen 0.3.0
File Interpreter ABI Platform
py2aspen-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 45.8 kB

Release files / py2aspen-0.3.0.tar.gz

Download URL py2aspen-0.3.0.tar.gz
Size 20.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2b0906147138562d154fc9278a6022f5c5b2327b04a1af0365f03626006cb517
BLAKE2b-256 checksum
How to use checksums
02a194a2520d1ab02ae517a3f07933869cfcd3b20d6bc0dd41e93144dfecb364
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / py2aspen-0.3.0-py3-none-any.whl

Download URL py2aspen-0.3.0-py3-none-any.whl
Size 25.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c43536311671d78a16246b9e3bfb2ee3fd8e13d46ecc3805280f6a9a5884babf
BLAKE2b-256 checksum
How to use checksums
30a77584a5d86666ad4eaaab9290acffbe193899509c37c61e44f536cf7d54d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page