# Check NTP synchronization status from Python

**URL:** <https://forums.balena.io/t/check-ntp-synchronization-status-from-python/1262>\
**Category:** Product support\
**Created:** [June 19, 2017, 8:18am UTC](https://forums.balena.io/t/check-ntp-synchronization-status-from-python/1262 "2017-06-19T08:18:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tjc42](https://avatars.discourse-cdn.com/v4/letter/t/b38774/32.png) [@tjc42](https://forums.balena.io/u/tjc42)\
**Post date:** [June 19, 2017, 8:18am UTC](https://forums.balena.io/t/check-ntp-synchronization-status-from-python/1262/1 "2017-06-19T08:18:45Z")

</div>

Does anyone have an example of how to query the NTP synchronization state from Python using the dbus library?

I can get it to work from the command line using the instructions [here](https://docs.resin.io/runtime/runtime/#checking-if-device-time-is-ntp-synchronized), but I’m struggling to work out how to do this from the Python library.

---

<div class="post-metadata">

**Author:** ![imrehg](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/imrehg/32/36_2.png) [@imrehg](https://forums.balena.io/u/imrehg)\
**Post date:** [June 19, 2017, 10:28am UTC](https://forums.balena.io/t/check-ntp-synchronization-status-from-python/1262/2 "2017-06-19T10:28:49Z")

</div>

Hey, it takes a bit of trial and error to work with dbus, but it’s not too bad after a while 🙂

Here’s a minimal example:

```python
import python
bus = dbus.SystemBus()
proxy = bus.get_object('org.freedesktop.timedate1',
                       '/org/freedesktop/timedate1')
interface = dbus.Interface(proxy, 'org.freedesktop.DBus.Properties')
properties = interface.GetAll('org.freedesktop.timedate1')
print(properties)

```

If you are interested, here’s an expanded example (to show some dbus type conversions and suchalike), but this above should be enough to get started.

> **[balena-io-playground/balena-python-ntp-dbus](https://github.com/balena-io-playground/balena-python-ntp-dbus)**
>
> Example to query NTP status over DBUS on a resin.io device - balena-io-playground/balena-python-ntp-dbus

Please note that this example is in our “playground” so it’s not guaranteed to work all the time (I’ve just tested it now).

---

<div class="post-metadata">

**Author:** ![tjc42](https://avatars.discourse-cdn.com/v4/letter/t/b38774/32.png) [@tjc42](https://forums.balena.io/u/tjc42)\
**Post date:** [June 19, 2017, 11:03am UTC](https://forums.balena.io/t/check-ntp-synchronization-status-from-python/1262/3 "2017-06-19T11:03:24Z")

</div>

Super - many thanks.
