# Script function with a keyword args dictionnary

**URL:** <https://forum.inductiveautomation.com/t/script-function-with-a-keyword-args-dictionnary/34660>\
**Category:** Module Development\
**Tags:** ignition80\
**Created:** [May 12, 2020, 4:53pm UTC](https://forum.inductiveautomation.com/t/script-function-with-a-keyword-args-dictionnary/34660 "2020-05-12T16:53:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [May 12, 2020, 4:53pm UTC](https://forum.inductiveautomation.com/t/script-function-with-a-keyword-args-dictionnary/34660/1 "2020-05-12T16:53:40Z")

</div>

When a script function has a **keyword args dictionnary** ,  
what is the bast practice to convert the args for the java world…and obtain an HashMap object

```auto
PyArgumentMap args = PyArgumentMap.interpretPyArgs(pyArgs, keywords, AbstractScriptModule.class, "myFunction");
...args.get("myDicArgs")

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 12, 2020, 4:55pm UTC](https://forum.inductiveautomation.com/t/script-function-with-a-keyword-args-dictionnary/34660/2 "2020-05-12T16:55:06Z")

</div>

`PyArgumentMap` _is_ a `HashMap`. Did whoever wrote it do that for no reason or is that what you want?

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [May 12, 2020, 5:01pm UTC](https://forum.inductiveautomation.com/t/script-function-with-a-keyword-args-dictionnary/34660/3 "2020-05-12T17:01:16Z")

</div>

my script function has multiple args with some optionnal.  
one of those args is intended to be a dictionnary

for String, Interger args … we have args.getString(), …  
but args.get() return an Object, I need to cast it to a map

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 12, 2020, 5:07pm UTC](https://forum.inductiveautomation.com/t/script-function-with-a-keyword-args-dictionnary/34660/4 "2020-05-12T17:07:49Z")

</div>

Ah, I see. The value for that argument is probably a `PyDictionary` then?

---

<div class="post-metadata">

**Author:** ![mazeyrat](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mazeyrat/32/10955_2.png) [@mazeyrat](https://forum.inductiveautomation.com/u/mazeyrat)\
**Post date:** [May 12, 2020, 5:14pm UTC](https://forum.inductiveautomation.com/t/script-function-with-a-keyword-args-dictionnary/34660/5 "2020-05-12T17:14:43Z")

</div>

Yes it’s a PyDictionary. Is tyhere any built-in sdk function to convert to an HashMap ?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 12, 2020, 5:20pm UTC](https://forum.inductiveautomation.com/t/script-function-with-a-keyword-args-dictionnary/34660/6 "2020-05-12T17:20:55Z")

</div>

`PyDictionary` is already a `ConcurrentMap` (so, a `Map`).

Create a copy if you want: `new HashMap(dictionary)`

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 12, 2020, 5:28pm UTC](https://forum.inductiveautomation.com/t/script-function-with-a-keyword-args-dictionnary/34660/7 "2020-05-12T17:28:25Z")

</div>

If you can bump the SDK version to 8.0.11 or higher, you can use PyUtilities, which has a few utility methods; you would `com.inductiveautomation.ignition.common.PyUtilities#streamEntries` then use the collector implementation in the same file (or roll your own). As Kevin points out, it’s already a map (of PyObjects), so you will probably want to use `TypeUtilities.pyToJava()` on individual elements to get native Java types.

If you do bump the SDK version, you can also use PyArgParser, which is (in my opinion, at least, since I wrote it 🙂) a bit nicer to use re: type coercion. It also has a `getAsMap()` method, so you can retrieve a user-supplied argument as a (Java typed) map in one line:  
`com.inductiveautomation.ignition.common.script.PyArgParser#getAsMap(java.lang.String, java.lang.Class<K>, java.lang.Class<V>)`
