Author Topic: Python win32com is very, very slow  (Read 775 times)

keesbghs

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Python win32com is very, very slow
« on: April 22, 2025, 10:41:56 pm »
Hi,
With the Python win32com module it is possible to read the details of Packages, Elements and Realizes. I've used information from
https://sparxsystems.com/enterprise_architect_user_guide/17.0/add-ins___scripting/repository3.html
https://sparxsystems.com/enterprise_architect_user_guide/17.0/add-ins___scripting/package_2.html
https://sparxsystems.com/enterprise_architect_user_guide/17.0/add-ins___scripting/element2.html
I'm getting the data that I want to see.

But it is really, really slow. I have just some 200 elements, which takes almost 6 minutes (!!!) to read.

Did anyone else see this too? What can I do to speed it up?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Python win32com is very, very slow
« Reply #1 on: April 22, 2025, 11:16:01 pm »
The API is very slow whenever you need to loop EA.Collections such as Package.Packages, Package.Elements, Element.Connectors, etc...

The workaround is to use Repository.SQLQuery to get the info you need.
This uses an SQL Query to the database, which is way faster.
In you example it would probably be less then 6 seconds instead of 6 minutes.

Geert

keesbghs

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: Python win32com is very, very slow
« Reply #2 on: April 23, 2025, 06:57:56 pm »
I had already written some Python code with SQLalchemy, which is indeed much faster. The only problem is that this is basically some sort of reverse engineering. I don't (yet?) want to use that to write into the database.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Python win32com is very, very slow
« Reply #3 on: April 23, 2025, 08:54:24 pm »
I had already written some Python code with SQLalchemy, which is indeed much faster. The only problem is that this is basically some sort of reverse engineering. I don't (yet?) want to use that to write into the database.

I almost never write directly to the database, but whenever I need to query the model I almost always use SQL rather than traversing EA.Collections.
Updating a model is still done over the API. There are methods such as Repository.GetElementByID() that get you the required API object from your query results.

Geert