py2aspen

作者 adk23333 · 版本 1.0.0 · 更新于 2026-10-19 00:45 ·72.1 KB

基于 comtypes 的 Aspen Plus Python 封装库,提供面向对象的 API,可连接应用、打开 bkp 文件、在流程图上放置和连接模块与物流、读写属性、运行模拟并导出报告,支持本地 COM 与 DCOM 远程连接。

AspenPlusPython封装COM自动化流程模拟化工

✓已通过基础校验

名称、分类、版本与作者信息完整,安装包与文档齐备。

✓可直接使用

提供 Markdown 文档与配置示例,下载后按文档说明使用即可。

Skill 详情

py2aspen

py2aspen

A Python wrapper for Aspen Plus built on comtypes ✨

基于 comtypes 构建的 Aspen Plus Python 封装库 ✨


PyPI version
Python
Downloads
Stars
Issues
License


PyPI version
Python
Downloads
Stars
Issues
License


comtypes
uv
ty
ruff
QQ Group


comtypes
uv
ty
ruff
QQ Group

English | 简体中文

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.

一个基于 comtypes 构建的 Aspen Plus Python 封装库,将 COM 自动化调用封装为面向对象的 Python API:连接应用程序、打开 .bkp 文件、在流程图上放置/连接模块和物流、读写属性、运行模拟以及导出报告。它同时支持本地 COM 和基于 DCOM 的远程连接。

Installation

安装

Install with uv (recommended) or pip:

使用 uv(推荐)或 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.

with 代码块会自动调用 lazy_bind() 以启用后期绑定,并在退出时关闭 Aspen Plus。若希望在脚本结束后保持应用程序窗口打开(例如用于调试),请跳过 with,改为手动调用 lazy_bind()。

Development workflow (uv + ty + ruff)

开发工作流(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.

本项目采用 src 布局,以 uv_build 作为构建后端。依赖管理由 uv 负责,类型检查由 ty 负责,代码风格由 ruff 负责。

Generate the comtypes type module

生成 comtypes 类型模块

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/): py2aspen 依赖 comtypes.gen.Happ(Aspen Plus 类型库)。仓库中已在 tlb/v14/happ.tlb 提供了 .tlb 文件;安装完成后,在目标 Python 环境中生成一次即可(输出写入 <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.
在重建虚拟环境或删除 comtypes/gen/ 目录后,请重新运行此命令。

Environment and dependencies

环境与依赖

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

Type checking (ty)

类型检查(ty)

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

Code style (ruff)

代码风格(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

Project Status

Contributors

贡献者

Thanks to everyone who contributes to py2aspen!

感谢所有为 py2aspen 做出贡献的人!

Contributors![contributors)

Contributors![contributors)

Special thanks to the friends in our chat group:

特别感谢我们聊天群中的朋友们:

QQ: 562721026

QQ:562721026

TG: None

TG:无

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

AspenPlus-Python-Interface - 一个充当 API 的 Python 接口,用于自动化设计综合。它包含 RADFRAC、DSTWU、Flash2、RYield、RPlug、RCSTR、Heater、Mixer、Splitter 的所有变量,并包含一个来自 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.

欢迎任何形式的贡献:提交 Issue 来报告问题或建议新功能,或提交 Pull Request 来改进代码。

下载后解压即可使用
梦马论坛-以梦为马,不负韶华

化工人的交流乐园

联系我们

  • 投诉建议 相关侵权、举报、投诉及建议等,请发 E-mail:admin@meng.horse
返回顶部