# Newbie question: how to organize Python files when developing module with some complex logic?

**URL:** <https://forum.ansible.com/t/newbie-question-how-to-organize-python-files-when-developing-module-with-some-complex-logic/1940>\
**Category:** Get Help\
**Created:** [October 25, 2023, 7:17am UTC](https://forum.ansible.com/t/newbie-question-how-to-organize-python-files-when-developing-module-with-some-complex-logic/1940 "2023-10-25T07:17:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin.huber](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/martin.huber/32/1324_2.png) [@martin.huber](https://forum.ansible.com/u/martin.huber)\
**Post date:** [October 25, 2023, 7:17am UTC](https://forum.ansible.com/t/newbie-question-how-to-organize-python-files-when-developing-module-with-some-complex-logic/1940/1 "2023-10-25T07:17:59Z")

</div>

Hi,

I am currently developing an Ansible role, that allows me to sync some configuration by the means of the REST API of a 3rd party product to configure this product.

This involves some complex analysis and quite a couple of REST calls.

So I started implementing an Ansible module doing that sync.

I organized the main entry point of the module in the /library subdirectory of the role and the real implementation in the /module\_utils directory within the role.

During the work I also did some refactoring of the code, extracting model classes in a model.py, and some other functionality to respective python files to keep things together.  
I yet only am testing manually with a python file that just executes the functions in the files in the module\_utils directory.

When I now tried it the first time from my Ansible playbook, it was unable to find the imports of the helper files in module\_utils.  
More precise: the primary class was imported to the module code with an import from ansible.module\_util.my\_python\_file - but my\_python\_file imported the “sibbling” files directly.  
The playbook execution now is complaining about unknown modules.  
So my impression is, that I also would have to import a sibbling from “ansible.module\_util.sibbling” instead of from “sibbling” only …  
But this would disallow for local testing w/o using the ansible playbook.

What am I doing wrong ?  
Should I treat the python code by itself, and create a pip package from it and just require this from the Module ?

How would you organize your files to be efficient during development ?

Thanks a lot!  
Martin

---

<div class="post-metadata">

**Author:** ![martin.huber](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/martin.huber/32/1324_2.png) [@martin.huber](https://forum.ansible.com/u/martin.huber)\
**Post date:** [October 25, 2023, 5:17pm UTC](https://forum.ansible.com/t/newbie-question-how-to-organize-python-files-when-developing-module-with-some-complex-logic/1940/2 "2023-10-25T17:17:29Z")

</div>

Ok, I was able to solve part of the problem by using relative imports all over my module\_utils code.

Single thing that still is annoying:  
the module code itself still needs to import from ansible.module\_utils… - what is not known by my IDE during development time.

Any thoughts to this ?

Thanks !
