# Can we Run the robot keywords from python file

**URL:** <https://forum.robotframework.org/t/can-we-run-the-robot-keywords-from-python-file/3996>\
**Category:** SeleniumLibrary\
**Created:** [13 June 2022 15:46 UTC](https://forum.robotframework.org/t/can-we-run-the-robot-keywords-from-python-file/3996 "2022-06-13T15:46:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sharansiddesh](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Sharansiddesh](https://forum.robotframework.org/u/Sharansiddesh)\
**Post date:** [13 June 2022 15:46 UTC](https://forum.robotframework.org/t/can-we-run-the-robot-keywords-from-python-file/3996/1 "2022-06-13T15:46:40Z")

</div>

Hi All

I have written some of the robot keywords in robot file  
Is there any way that I can run the keywords from the python file and get the returning value in python file

Regards  
Sharan

---

<div class="post-metadata">

**Author:** ![burr](https://avatars.discourse-cdn.com/v4/letter/b/8c91f0/32.png) [@burr](https://forum.robotframework.org/u/burr)\
**Post date:** [13 June 2022 16:57 UTC](https://forum.robotframework.org/t/can-we-run-the-robot-keywords-from-python-file/3996/2 "2022-06-13T16:57:51Z")

</div>

You can call the various `Run Keyword *` keywords from BuiltIn in Python, some of which return values.

I have not tried:

```python
from robot.libraries.BuiltIn import BuiltIn
...
val = BuiltIn().run_keyword("keyword", locator)

```

directly, but it might do what you need.

---

<div class="post-metadata">

**Author:** ![Sharansiddesh](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Sharansiddesh](https://forum.robotframework.org/u/Sharansiddesh)\
**Post date:** [14 June 2022 05:49 UTC](https://forum.robotframework.org/t/can-we-run-the-robot-keywords-from-python-file/3996/3 "2022-06-14T05:49:49Z")

</div>

> [@burr](#):
>
> ```python
> from robot.libraries.BuiltIn import BuiltIn
> ...
> val = BuiltIn().run_keyword("keyword", locator)
> 
> ```

Hi Burr,

Thanks for the replay

i have tried this but its giving error “robot.libraries.BuiltIn.RobotNotRunningError: Cannot access execution context”

Thanks  
sharan

---

<div class="post-metadata">

**Author:** ![aaltat](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/aaltat/32/15_2.png) [@aaltat](https://forum.robotframework.org/u/aaltat)\
**Post date:** [14 June 2022 16:35 UTC](https://forum.robotframework.org/t/can-we-run-the-robot-keywords-from-python-file/3996/4 "2022-06-14T16:35:05Z")

</div>

It only works when Robot Framework execution is ongoing in the same Python processes.

---

<div class="post-metadata">

**Author:** ![jaime.salazar](https://avatars.discourse-cdn.com/v4/letter/j/da6949/32.png) [@jaime.salazar](https://forum.robotframework.org/u/jaime.salazar)\
**Post date:** [8 March 2023 10:42 UTC](https://forum.robotframework.org/t/can-we-run-the-robot-keywords-from-python-file/3996/5 "2023-03-08T10:42:28Z")

</div>

Hi @aaltat, then how can I get the Robot Framework execution up and running before running the Python file?

In my case, I’m trying to use `BuiltIn().run_keyword()` inside a test, running it with pytest, but I am also getting `RobotNotRunningError`.

Btw, I’m running pytest with the VSCode extension, setting a task in `robot.yaml`:

```
tasks:
  Run Python:
    shell: python -m pytest

```

I’ve also tried with `rcc run`. I would expect these two scenarios to have the Robot Execution up and running…

---

<div class="post-metadata">

**Author:** ![aaltat](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/aaltat/32/15_2.png) [@aaltat](https://forum.robotframework.org/u/aaltat)\
**Post date:** [26 March 2023 11:39 UTC](https://forum.robotframework.org/t/can-we-run-the-robot-keywords-from-python-file/3996/6 "2023-03-26T11:39:09Z")

</div>

Execution of the keyword is not possible if Robot Framework is not running. If you are trying to execute library keyword, then you need to call the equivalent Python method.
