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

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

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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py2aspen-0.1.1.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py2aspen-0.1.1-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file py2aspen-0.1.1.tar.gz.

File metadata

  • Download URL: py2aspen-0.1.1.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","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}

File hashes

Hashes for py2aspen-0.1.1.tar.gz
Algorithm Hash digest
SHA256 82f7ff234a6f541b3d3048a2e70cfc15ba59507a88be8d373cfc05fc251e1e1f
MD5 97ed593dc35c0d2b27835e5b4751709c
BLAKE2b-256 0d25d3fcdef7be356374145037f3ef7c7a3663d6084945da5bed9b3dd7096dd6

See more details on using hashes here.

File details

Details for the file py2aspen-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: py2aspen-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","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}

File hashes

Hashes for py2aspen-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3d2ba05d37e9f54e103a2949c210fd0753c51d4d40b50921bd46776069ff66d8
MD5 5cf711e9fe6a53de106702ca888aaf85
BLAKE2b-256 944e1d21c3b46f721a38ba43aad27a940d4a33ef4950e6bd4b2660f8048f8bd1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page