# Python module for easily accessing the openHAB REST API

**URL:** <https://community.openhab.org/t/python-module-for-easily-accessing-the-openhab-rest-api/19449>\
**Category:** Runtime\
**Tags:** python, openhab2\
**Created:** [January 4, 2017, 12:22am UTC](https://community.openhab.org/t/python-module-for-easily-accessing-the-openhab-rest-api/19449 "2017-01-04T00:22:57Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![KataPi](https://community.openhab.org/letter_avatar_proxy/v4/letter/k/91b2a8/32.png) [@KataPi](https://community.openhab.org/u/KataPi)\
**Post date:** [July 3, 2017, 8:01am UTC](https://community.openhab.org/t/python-module-for-easily-accessing-the-openhab-rest-api/19449/7 "2017-07-03T08:01:05Z")

</div>

Hi All  
(my first post)

@sim0nx I like your work.  
I’m a noob but I’d like to learn this module.  
Can you give some exemples for switch and contact?  
I’m running openhab2 on raspberry pi 2 and I try to turn on/off a led.

My wrong code is

Items  
`Switch led "Led" (Lights) { gpio="pin:16" }`

python-openhab

```
from openhab import openHAB
base_url = 'http://localhost:8080/rest'
openhab = openHAB(base_url)
# fetch all items
items = openhab.fetch_all_items()

gg = items.get('led')
print(gg.state)
gg.on()

```

OH2 printe OFF state and turn ON my switch but don’t turn ON my led  
events.log  
`[ItemStateChangedEvent] - led changed from OFF to ON`

When I switch through BasicUI or Android app led turn ON  
events.log

```
[ItemCommandEvent] - Item 'led' received command ON
[ItemStateChangedEvent] - led changed from OFF to ON

```

…and led works.

Someone can help me?

---

_[View the full topic](https://community.openhab.org/t/python-module-for-easily-accessing-the-openhab-rest-api/19449)._
