# How do I get import myFile to work? (importing into actions.py)

**URL:** <https://forum.rasa.com/t/how-do-i-get-import-myfile-to-work-importing-into-actions-py/41687>\
**Category:** Rasa Open Source\
**Created:** [March 24, 2021, 8:23pm UTC](https://forum.rasa.com/t/how-do-i-get-import-myfile-to-work-importing-into-actions-py/41687 "2021-03-24T20:23:40Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![john.mcquaid](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/john.mcquaid/32/14508_2.png) [@john.mcquaid](https://forum.rasa.com/u/john.mcquaid)\
**Post date:** [March 24, 2021, 8:23pm UTC](https://forum.rasa.com/t/how-do-i-get-import-myfile-to-work-importing-into-actions-py/41687/1 "2021-03-24T20:23:40Z")

</div>

I have a separate python script, saved within the same directory as the actions.py, that I made. I want to import that file into my actions.py file so that I can expand upon the features while keeping an orderly/well organized system. I have had zero issues importing other libraries; However, all other libraries are from 3rd parties. I am wondering if you cannot import your own files? Anyway, please let me know if I am stupid or this is just not possible. I am just not familiar with python enough I guess.

---

<div class="post-metadata">

**Author:** ![fkoerner](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/fkoerner/32/11784_2.png) [@fkoerner](https://forum.rasa.com/u/fkoerner)\
**Post date:** [March 25, 2021, 8:04am UTC](https://forum.rasa.com/t/how-do-i-get-import-myfile-to-work-importing-into-actions-py/41687/2 "2021-03-25T08:04:38Z")

</div>

You can definitely import your own file! It sound like what you’re looking for is called a [relative import](https://docs.python.org/3/reference/import.html#package-relative-imports). So for example:

`from . import myFile`

or:

`from .myFile import my_function`

---

<div class="post-metadata">

**Author:** ![john.mcquaid](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/john.mcquaid/32/14508_2.png) [@john.mcquaid](https://forum.rasa.com/u/john.mcquaid)\
**Post date:** [March 25, 2021, 1:06pm UTC](https://forum.rasa.com/t/how-do-i-get-import-myfile-to-work-importing-into-actions-py/41687/3 "2021-03-25T13:06:52Z")

</div>

Thank you so much @fkoerner! Wow, that’s embarrassing. I am brand new to python, so hopefully my issue is excusable for beginners. 🤨

---

<div class="post-metadata">

**Author:** ![fkoerner](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/fkoerner/32/11784_2.png) [@fkoerner](https://forum.rasa.com/u/fkoerner)\
**Post date:** [March 25, 2021, 2:44pm UTC](https://forum.rasa.com/t/how-do-i-get-import-myfile-to-work-importing-into-actions-py/41687/4 "2021-03-25T14:44:04Z")

</div>

You’re welcome! No need to be embarrassed: everyone starts as a beginner 🙂

Happy bot-building!

---

<div class="post-metadata">

**Author:** ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)\
**Post date:** [March 25, 2021, 8:25pm UTC](https://forum.rasa.com/t/how-do-i-get-import-myfile-to-work-importing-into-actions-py/41687/5 "2021-03-25T20:25:59Z")

</div>

Hello @fkoerner! Sorry, I know that’s not Rasa related but…

I’ve written helper functions and global variables in `actions.py`.

If I want to split my actions file into let’s say, an action file for a particular form, an action file for this kind of responses, etc.

So, in the main `actions.py` file, I can import the other files. But if a custom action needs to access a helper function defined in `actions.py`, do I need to import the files in each other? For example:

- `actions.py`: `from . import other_actions`
- `other_actions.py`: `from . import actions`

---

<div class="post-metadata">

**Author:** ![john.mcquaid](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/john.mcquaid/32/14508_2.png) [@john.mcquaid](https://forum.rasa.com/u/john.mcquaid)\
**Post date:** [March 25, 2021, 9:19pm UTC](https://forum.rasa.com/t/how-do-i-get-import-myfile-to-work-importing-into-actions-py/41687/6 "2021-03-25T21:19:28Z")

</div>

@ChrisRahme, you can import all your own files into your actions.py file. I have also found another thread looked as though someone got their rasa to run multiple actions.py files. Here is that [thread](http://forum.rasa.com/t/can-we-have-multiple-action-py-file-in-a-project/6907/2). What I have done was import my additional actions files directly into my actions.py file. The files that were mine are the “EmailFunctions” and the “LoadData” (as seen in the image below).

![Untitled](https://europe1.discourse-cdn.com/flex013/uploads/rasa/original/2X/f/f544a1af3a087036c8203b5c440e24ecc11da499.png)

---

<div class="post-metadata">

**Author:** ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)\
**Post date:** [March 25, 2021, 9:23pm UTC](https://forum.rasa.com/t/how-do-i-get-import-myfile-to-work-importing-into-actions-py/41687/7 "2021-03-25T21:23:05Z")

</div>

Thanks for your answer. I created a `common.py` file with global variables that I’m importing in each file. Haven’t tested it yet though.

I also found [this](http://forum.rasa.com/t/deploy-actions-server-with-multiple-custom-actions-file/28100/3) which helped.

---

<div class="post-metadata">

**Author:** ![fkoerner](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/fkoerner/32/11784_2.png) [@fkoerner](https://forum.rasa.com/u/fkoerner)\
**Post date:** [March 26, 2021, 7:04am UTC](https://forum.rasa.com/t/how-do-i-get-import-myfile-to-work-importing-into-actions-py/41687/8 "2021-03-26T07:04:19Z")

</div>

Hi @ChrisRahme, looks like you already got the help you needed! I’ll add that what you described above:

- `actions.py`: `from . import other_actions`
- `other_actions.py`: `from . import actions`

is a cyclic import (module A imports module B, and module B imports module A). This isn’t always a problem, but it can become one. Little anecdote [here](https://rebelsky.cs.grinnell.edu/musings/cyclic-imports-python).

What you describe later is a better pattern – put the methods and constants you want to import into both action files into a `common.py`.

---

<div class="post-metadata">

**Author:** ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)\
**Post date:** [March 26, 2021, 7:09am UTC](https://forum.rasa.com/t/how-do-i-get-import-myfile-to-work-importing-into-actions-py/41687/9 "2021-03-26T07:09:59Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![kutub](https://avatars.discourse-cdn.com/v4/letter/k/51bf81/32.png) [@kutub](https://forum.rasa.com/u/kutub)\
**Post date:** [May 3, 2024, 7:22am UTC](https://forum.rasa.com/t/how-do-i-get-import-myfile-to-work-importing-into-actions-py/41687/10 "2024-05-03T07:22:12Z")

</div>

Suppose, there are too many actions in actions.py file so if i want to seperate some actions in other file so how can i import them into main actions file??
