# Dynamo API in python node?

**URL:** <https://forum.dynamobim.com/t/dynamo-api-in-python-node/16361>\
**Category:** Developers\
**Tags:** python, dynamo, api\
**Created:** [November 9, 2017, 4:25pm UTC](https://forum.dynamobim.com/t/dynamo-api-in-python-node/16361 "2017-11-09T16:25:57Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakob.lilliemarck](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@jakob.lilliemarck](https://forum.dynamobim.com/u/jakob.lilliemarck)\
**Post date:** [November 9, 2017, 4:25pm UTC](https://forum.dynamobim.com/t/dynamo-api-in-python-node/16361/1 "2017-11-09T16:25:57Z")

</div>

Hey,  
I’m trying to acces Dynamo API from a dynamo python node but I can’t find any solid documentation on how to import the library and use the classes?

More specifically I would like to retrieve the name and version of the current dynamo file from from `Dynamo.Graph.Workspaces.WorkspaceModel` (see: [http://dynamods.github.io/DynamoAPI/Dynamo\_Graph\_Workspaces/WorkspaceInfo/#workspaceinfo](http://dynamods.github.io/DynamoAPI/Dynamo_Graph_Workspaces/WorkspaceInfo/#workspaceinfo))

Very thankful for any help on the matter, the name of the library to import would be a great start!

Best

Jakob

---

<div class="post-metadata">

**Author:** ![Kulkul](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/kulkul/32/49801_2.png) [@Kulkul](https://forum.dynamobim.com/u/Kulkul)\
**Post date:** [November 9, 2017, 4:56pm UTC](https://forum.dynamobim.com/t/dynamo-api-in-python-node/16361/2 "2017-11-09T16:56:30Z")

</div>

Hi @jakob.lilliemarck

> [@Refering to a relative path](https://forum.dynamobim.com/t/refering-to-a-relative-path/16293/2):
>
> try the Graph.FilePath node from the SpringsUI package:

---

<div class="post-metadata">

**Author:** ![jakob.lilliemarck](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@jakob.lilliemarck](https://forum.dynamobim.com/u/jakob.lilliemarck)\
**Post date:** [November 10, 2017, 7:44am UTC](https://forum.dynamobim.com/t/dynamo-api-in-python-node/16361/3 "2017-11-10T07:44:58Z")

</div>

Thanks @Kulkul, that node indeed works and I’ll use it as a temporary solution.  
The node is however closed and the source cannot be viewed.I’m interested in finding out how to do this in a python node using the dynamo API.

Any thoughts?

---

<div class="post-metadata">

**Author:** ![jakob.lilliemarck](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@jakob.lilliemarck](https://forum.dynamobim.com/u/jakob.lilliemarck)\
**Post date:** [November 30, 2017, 10:45am UTC](https://forum.dynamobim.com/t/dynamo-api-in-python-node/16361/4 "2017-11-30T10:45:03Z")

</div>

Hey again,  
The question remains the same. Is it possible to import and use the Dynamo API (link below) in a Dynamo Python node? Im trying “import Dynamo” but the module is not recognized, and I have a really hard time finding any examples of people using the API in a Python node?

Dynamo API I would like to use in my Python node:  
[http://dynamods.github.io/DynamoAPI/](http://dynamods.github.io/DynamoAPI/)

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [November 30, 2017, 2:46pm UTC](https://forum.dynamobim.com/t/dynamo-api-in-python-node/16361/5 "2017-11-30T14:46:02Z")

</div>

```
clr.AddReference('DSCoreNodes')
from DSCore import *

```

This will give you access to Dynamo nodes in Python. Try using SpringsUI.Graph.FilePath to get the name and Get This Dynamo Version from Bakery to get the current version.

---

<div class="post-metadata">

**Author:** ![Michael\_Kirschner2](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/michael_kirschner2/32/75576_2.png) [@Michael\_Kirschner2](https://forum.dynamobim.com/u/Michael_Kirschner2)\
**Post date:** [December 1, 2017, 2:53am UTC](https://forum.dynamobim.com/t/dynamo-api-in-python-node/16361/6 "2017-12-01T02:53:38Z")

</div>

I have not tried - you should look at the dynamo source in c# to see how the constructor for WorkspaceModel is used. It should be possible to essentially build a whole new workspaceModel inside your graph. (using python or zero touch)

It would be a fun project to wrap dynamo core into a set of nodes…

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [December 1, 2017, 1:25pm UTC](https://forum.dynamobim.com/t/dynamo-api-in-python-node/16361/7 "2017-12-01T13:25:00Z")

</div>

> [@Michael\_Kirschner2](#):
>
> It would be a fun project to wrap dynamo core into a set of nodes…

Dynamo-ception!

---

<div class="post-metadata">

**Author:** ![jakob.lilliemarck](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@jakob.lilliemarck](https://forum.dynamobim.com/u/jakob.lilliemarck)\
**Post date:** [December 4, 2017, 4:38pm UTC](https://forum.dynamobim.com/t/dynamo-api-in-python-node/16361/8 "2017-12-04T16:38:30Z")

</div>

@Nick_Boyts  
Thanks for the tip.  
Altough i’m not really looking to access predefined nodes, I would be very interested in where to find the documentation on the import names? More specifically I would like to access DynamoModel to listen in on “RunCompleted”-event among others. Since you know how to import the nodes, do you know where to find information on other possible imports?

If there’s any Dynamo dev listening in on this - Intellisense in the python node would be a really great addition, even in its simplest form.

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [December 4, 2017, 5:17pm UTC](https://forum.dynamobim.com/t/dynamo-api-in-python-node/16361/9 "2017-12-04T17:17:33Z")

</div>

I looked into it a while ago. Unfortunately I didn’t have any luck.  
Are the nodes I mentioned above what you’re looking for?

---

<div class="post-metadata">

**Author:** ![Michael\_Kirschner2](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/michael_kirschner2/32/75576_2.png) [@Michael\_Kirschner2](https://forum.dynamobim.com/u/Michael_Kirschner2)\
**Post date:** [December 5, 2017, 2:22am UTC](https://forum.dynamobim.com/t/dynamo-api-in-python-node/16361/10 "2017-12-05T02:22:24Z")

</div>

it will be much easier to do this with a c# zero touch node as you can just reference the dynamo core dlls and get intellisense / inspect them, you can use our nuget packages (search for dynamo visual programming on nuget)

---

<div class="post-metadata">

**Author:** ![jakob.lilliemarck](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@jakob.lilliemarck](https://forum.dynamobim.com/u/jakob.lilliemarck)\
**Post date:** [December 5, 2017, 7:57am UTC](https://forum.dynamobim.com/t/dynamo-api-in-python-node/16361/11 "2017-12-05T07:57:04Z")

</div>

@Nick_Boyts  
Not really, but I might be able to use them to work around my problem. Thanks for mentioning them!

@Michael_Kirschner2  
Thanks for the tip, I’ll try and see if we got any pooled visual studio licences around, and look into it. Unfortunatly I think we’ve outgrown the community version 😕

Just to clarify what I really want to do, **I would like to get some metadata about the dynamo-script ‘run’ to pack up in a json-bundle and send to server to track some user data on our scripts internally. I would like to do this using Python in Dynamo (Im not a C# whiz). For instance, I’m interested in logging how long the ‘run’ took and any warnings, errors or crash messages that occured, etc.**

I’ve been looking into the dynamo-log file, and while some of the data i’m interested in is in there, there is also so much data there that we don’t want. I figured there should be an easier way to just get the values we’re after using the API rather than parsing the log file.

---

<div class="post-metadata">

**Author:** ![jakob.lilliemarck](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@jakob.lilliemarck](https://forum.dynamobim.com/u/jakob.lilliemarck)\
**Post date:** [December 5, 2017, 1:14pm UTC](https://forum.dynamobim.com/t/dynamo-api-in-python-node/16361/12 "2017-12-05T13:14:45Z")

</div>

Alright, so I’ve started looking into the DynamoCore.dll to see how to access the meta data that I want to log to server using Python and some commands Im interesting in using. As stated previously, I’m not a C# whiz…

Im stuck trying to get the `CurrentWorkspace` and `WorkspaceInfo` so that I’ll be able to get `FileName`, `HasRunWithoutCrash`, `RunPeriod` etc but also be able to `ForceRun()` and maybe even listen in on events.  
I’m trying this now:

```
clr.AddReference("DynamoCore")
import Dynamo
test = Dynamo.Models.DynamoModel.CurrentWorkspace. __get__ (???)

```

But `CurrentWorkspace` wants a `DynamoModel` as argument, and I thought that was what I was trying to get by calling it? Feels like I’m running in circles here, very thankful for any pointers!

Best

Jakob

---

<div class="post-metadata">

**Author:** ![Michael\_Kirschner2](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/michael_kirschner2/32/75576_2.png) [@Michael\_Kirschner2](https://forum.dynamobim.com/u/Michael_Kirschner2)\
**Post date:** [December 6, 2017, 12:19am UTC](https://forum.dynamobim.com/t/dynamo-api-in-python-node/16361/13 "2017-12-06T00:19:24Z")

</div>

hmm, take a look at the DynamoServices.dll that might be the most useful.  
You won’t be able to use DynamoCore from a python node to look at the current instance of Dynamo - you’d need to basically create a new DynamoModel inside the python engine and invoke it - but that won’t help you monitor your graph.

I think DynamoServices.dll will let you monitor current events, like workspace added, or evaluation complete.

---

<div class="post-metadata">

**Author:** ![jakob.lilliemarck](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@jakob.lilliemarck](https://forum.dynamobim.com/u/jakob.lilliemarck)\
**Post date:** [July 5, 2018, 8:24am UTC](https://forum.dynamobim.com/t/dynamo-api-in-python-node/16361/14 "2018-07-05T08:24:46Z")

</div>

I found a rather lenghty workaround scraping the data of the dynamo logfiles using a python regex.

Anyway, forcing a reevaluation of the script every time the graph is run is still a challange. I’ve been seeing requests for this funcitonality dating back to 2013 but no evidence it’s been fixed yet? Do you (or anyone else) know how to force a python node or a custom node to run every time the the ‘Run’ is pressed?  
I’d like to do this without any other third party package dependencies since that would make the script very error-prone as it’s supposed to be distributed.

---

<div class="post-metadata">

**Author:** ![john\_pierson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/john_pierson/32/191977_2.png) [@john\_pierson](https://forum.dynamobim.com/u/john_pierson)\
**Post date:** [July 5, 2018, 1:16pm UTC](https://forum.dynamobim.com/t/dynamo-api-in-python-node/16361/15 "2018-07-05T13:16:39Z")

</div>

@jakob.lilliemarck, Like this? _(Example is showing the node auto running when a new node is placed. I am outputting current time to show the change.)_

 ![20180705-ForcePythonUpdate](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/e/ce3dee6fa2f2eaf1431c0f6f51fd251c8c3c4b9b.gif)

---

<div class="post-metadata">

**Author:** ![Donovan.Wilson](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@Donovan.Wilson](https://forum.dynamobim.com/u/Donovan.Wilson)\
**Post date:** [June 18, 2019, 5:38pm UTC](https://forum.dynamobim.com/t/dynamo-api-in-python-node/16361/17 "2019-06-18T17:38:59Z")

</div>

How did you do this?

---

<div class="post-metadata">

**Author:** ![john\_pierson](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/john_pierson/32/191977_2.png) [@john\_pierson](https://forum.dynamobim.com/u/john_pierson)\
**Post date:** [June 18, 2019, 5:39pm UTC](https://forum.dynamobim.com/t/dynamo-api-in-python-node/16361/18 "2019-06-18T17:39:36Z")

</div>

I found out about accessing the Dynamo API in Python thanks to the Open-Source code provided by the great folks at DesignTech.

> **[GitHub - MarkThorley/designtechDynamo: designtech.io Dynamo Package Nodes](https://github.com/MarkThorley/designtechDynamo)**
>
> designtech.io Dynamo Package Nodes. Contribute to MarkThorley/designtechDynamo development by creating an account on GitHub.

Here is the thread with the python:

> [@Force Run Python](https://forum.dynamobim.com/t/force-run-python/31709):
>
> Hello all, @john_pierson shoes an example in the below post of a python node updating as things are changed. Do any of you know how he accomplished this?
