# Mimic multiple Python package namespaces in single module

**URL:** <https://forum.inductiveautomation.com/t/mimic-multiple-python-package-namespaces-in-single-module/54506>\
**Category:** Module Development\
**Created:** [December 28, 2021, 9:22pm UTC](https://forum.inductiveautomation.com/t/mimic-multiple-python-package-namespaces-in-single-module/54506 "2021-12-28T21:22:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![james.vosler](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@james.vosler](https://forum.inductiveautomation.com/u/james.vosler)\
**Post date:** [December 28, 2021, 9:22pm UTC](https://forum.inductiveautomation.com/t/mimic-multiple-python-package-namespaces-in-single-module/54506/1 "2021-12-28T21:22:16Z")

</div>

We would like to provide the implementation for multiple python package paths in the same ignition module. The sample code provides the example for registering a single path:

> ```
> manager.addScriptModule(
> Constants.NAMESPACE,
> scriptModule,
> new PropertiesFileDocProvider());
> 
> ```

The implementation of addScriptModule registers all the public methods from the object 'script module', so we would obviously need to separate the implementation else all functions would show up for every namespace/path.

However the getRPCHandler does not allow differentiation by class:

> ```
> @Override
> public Object getRPCHandler(ClientReqSession session, String projectName) {
> return scriptModule;
> }
> 
> ```

Can this be accomplished?

---

<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:** [December 28, 2021, 9:34pm UTC](https://forum.inductiveautomation.com/t/mimic-multiple-python-package-namespaces-in-single-module/54506/2 "2021-12-28T21:34:11Z")

</div>

Don’t use your script module instances as your RPC handler. Use something else that “multiplexes” the calls to the right place. Scripting and the RPC system are not related at all, except for that the examples use the RPC system to send client-scoped scripting calls to a gateway-scoped implementation.

---

<div class="post-metadata">

**Author:** ![james.vosler](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@james.vosler](https://forum.inductiveautomation.com/u/james.vosler)\
**Post date:** [December 28, 2021, 9:44pm UTC](https://forum.inductiveautomation.com/t/mimic-multiple-python-package-namespaces-in-single-module/54506/3 "2021-12-28T21:44:09Z")

</div>

If I understand correctly, we would also use the hook.getRPCHandler(…) when calling from a sibling module. The python package/path is no longer relevant, but segregating the methods to multiple objects is helpful for the programmer.

We have not found a way to multiplex the methods out to the script console properly just yet, but will keep working on it. Do you have an example for doing this?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 28, 2021, 11:08pm UTC](https://forum.inductiveautomation.com/t/mimic-multiple-python-package-namespaces-in-single-module/54506/4 "2021-12-28T23:08:50Z")

</div>

Break up your `scriptModule` implementation into separate classes, by the namespace the content is to be exposed in. Call `.addScriptModule()` for each, separately. If necessary, multiple implementation classes can be loaded into the same namespace, to selectively expose functionality. (By project, perhaps.)

Be aware that a namespace that does not begin with `system.` will not be auto-imported into other scopes, and might not be reachable at all.

---

<div class="post-metadata">

**Author:** ![james.vosler](https://avatars.discourse-cdn.com/v4/letter/j/8797f3/32.png) [@james.vosler](https://forum.inductiveautomation.com/u/james.vosler)\
**Post date:** [December 29, 2021, 8:55pm UTC](https://forum.inductiveautomation.com/t/mimic-multiple-python-package-namespaces-in-single-module/54506/5 "2021-12-29T20:55:08Z")

</div>

Here’s what worked:

1. We started with the sample script module code.
2. We created a separate interface and abstract base class for each python package/script file path that we wanted.
3. We created separate implementation classes for each interface/abstract base class for each context. These classes were passed to the addScriptModule functions.
4. On the gateway, we created an additional class that aggregated the gateway context’s implementation classes and implemented all of the interfaces, calling the appropriate implementation object as needed.

---

<div class="post-metadata">

**Author:** ![Jason\_Zhou](https://avatars.discourse-cdn.com/v4/letter/j/6bbea6/32.png) [@Jason\_Zhou](https://forum.inductiveautomation.com/u/Jason_Zhou)\
**Post date:** [July 27, 2023, 4:48pm UTC](https://forum.inductiveautomation.com/t/mimic-multiple-python-package-namespaces-in-single-module/54506/6 "2023-07-27T16:48:25Z")

</div>

Do you happen to still have this project saved, and would you be willing to upload it to a GitHub repository for reference? Many thanks if so.
