{% extends "layout.html" %} {% set title = 'PyTango documentation' %} {% set script_files = script_files + ["http://code.jquery.com/jquery-1.9.1.min.js", "_static/jssor.js", "_static/jssor.slider.js"] %} {% block body %}

# Welcome to PyTango documentation!

PyTango is a python module that exposes to Python the complete Tango C++ API. This means that you can write not only tango applications (scripts, CLIs, GUIs) that access tango device servers but also tango device servers themselves, all of this in pure python.

    # ----------------- server ------------------

    import time

    from PyTango.server import server_run
    from PyTango.server import Device, DeviceMeta
    from PyTango.server import attribute, command

    class Clock(Device):
        __metaclass__ = DeviceMeta

        time = attribute()

        def read_time(self):
            return time.time()

        @command(dtype_in=str, dtype_out=str)
        def strftime(self, tformat):
            return time.strftime(tformat)

    if __name__ == "__main__":
        server_run((Clock,))
    $ # ---------------- client -----------------

    $ python

    >>> from PyTango import DeviceProxy

    >>> clock = DeviceProxy("my/first/clock")

    >>> clock.time
    1384447223.774121

    >>> clock.read_attribute("time").value
    1384447252.037578

    >>> clock.strftime("%H:%M:%S")
    '17:41:50'

    >>> clock.command_inout("strftime",
    ...                     "%H:%M:%S")
    '17:43:12'

    >>> clock.status()
    'The device is in UNKNOWN state.'

    >>> # ---------- gevent client -----------

    >>> from PyTango.gevent import DeviceProxy

    >>> dev = DeviceProxy("sys/tg_test/1")
    >>> dev.get_green_mode()
    PyTango.GreenMode.Gevent

    >>> # Synchronous but green!
    >>> print(dev.state())
    RUNNING

    >>> # Asynchronous
    >>> res = dev.state(wait=False)
    >>> print(res)
    <gevent.event.AsyncResult at 0x1a74050>
    >>> print(res.get())
    RUNNING

    >>> # Synchronous, but green!
    >>> print(dev.long_scalar)
    832

    >>> # Asynchronous
    >>> res = dev.read_attribute("long_scalar",
    ...                          wait=False)
    >>> print(res)
    <gevent.event.AsyncResult at 0x1a9f54>
    >>> print(res.get())
    126
    >>> # ----- concurrent.futures client -----

    >>> from PyTango.futures import DeviceProxy

    >>> dev = DeviceProxy("sys/tg_test/1")
    >>> dev.get_green_mode()
    PyTango.GreenMode.Futures

    >>> # Synchronous
    >>> print(dev.state())
    RUNNING

    >>> # Asynchronous
    >>> res = dev.state(wait=False)
    >>> print(res)
    <Future at 0x34a9e51 state=pending>
    >>> print(res.result())
    RUNNING

    >>> # Synchronous
    >>> print(dev.long_scalar)
    832

    >>> # Asynchronous
    >>> res = dev.read_attribute("long_scalar",
    ...                          wait=False)
    >>> print(res)
    <Future at 0x5d8a17b state=pending>
    >>> print(res.result())
    126

Check out the getting started guide to learn how to build and/or install PyTango and after that the quick tour can help you with the first steps in the PyTango world. If you need help understanding what Tango itself really is, you can check the Tango homepage where you will find plenty of documentation, FAQ and tutorials.

{% endblock %}