i3ipc


Namei3ipc JSON
Version 2.2.1 PyPI version JSON
download
home_pagehttps://github.com/altdesktop/i3ipc-python
SummaryAn improved Python library to control i3wm and sway
upload_time2020-04-05 17:25:08
maintainer
docs_urlNone
authorTony Crisci
requires_python>=3.4.0
licenseBSD
keywords i3 i3wm extensions add-ons
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            
i3ipc-python
============

An improved Python library to control `i3wm <http://i3wm.org>`__ and `sway <https://swaywm.org/>`__.

About
-----

i3's interprocess communication (or `ipc <http://i3wm.org/docs/ipc.html>`__) is the interface i3wm uses to receive `commands <http://i3wm.org/docs/userguide.html#_list_of_commands>`__ from client applications such as ``i3-msg``. It also features a publish/subscribe mechanism for notifying interested parties of window manager events.

i3ipc-python is a Python library for controlling the window manager.  This project is intended to be useful for general scripting, and for applications that interact with the window manager like status line generators, notification daemons, and window pagers.

If you have an idea for a script to extend i3wm, you can add your script to the `examples folder <https://github.com/acrisci/i3ipc-python/tree/master/examples>`__.

For details on how to use the library, see the `reference documentation <https://i3ipc-python.readthedocs.io/en/latest/>`__.

Installation
------------

i3ipc is on `PyPI <https://pypi.python.org/pypi/i3ipc>`__.

``pip3 install i3ipc``

Example
-------

.. code:: python3

    from i3ipc import Connection, Event

    # Create the Connection object that can be used to send commands and subscribe
    # to events.
    i3 = Connection()

    # Print the name of the focused window
    focused = i3.get_tree().find_focused()
    print('Focused window %s is on workspace %s' %
          (focused.name, focused.workspace().name))

    # Query the ipc for outputs. The result is a list that represents the parsed
    # reply of a command like `i3-msg -t get_outputs`.
    outputs = i3.get_outputs()

    print('Active outputs:')

    for output in filter(lambda o: o.active, outputs):
        print(output.name)

    # Send a command to be executed synchronously.
    i3.command('focus left')

    # Take all fullscreen windows out of fullscreen
    for container in i3.get_tree().find_fullscreen():
        container.command('fullscreen')

    # Print the names of all the containers in the tree
    root = i3.get_tree()
    print(root.name)
    for con in root:
        print(con.name)

    # Define a callback to be called when you switch workspaces.
    def on_workspace_focus(self, e):
        # The first parameter is the connection to the ipc and the second is an object
        # with the data of the event sent from i3.
        if e.current:
            print('Windows on this workspace:')
            for w in e.current.leaves():
                print(w.name)

    # Dynamically name your workspaces after the current window class
    def on_window_focus(i3, e):
        focused = i3.get_tree().find_focused()
        ws_name = "%s:%s" % (focused.workspace().num, focused.window_class)
        i3.command('rename workspace to "%s"' % ws_name)

    # Subscribe to events
    i3.on(Event.WORKSPACE_FOCUS, on_workspace_focus)
    i3.on(Event.WINDOW_FOCUS, on_window_focus)

    # Start the main loop and wait for events to come in.
    i3.main()

Asyncio Support
---------------

Support for asyncio is included in the ``i3ipc.aio`` package. The interface is similar to the blocking interface but the methods that interact with the socket are coroutines.

.. code:: python3

    from i3ipc.aio import Connection
    from i3ipc import Event

    import asyncio

    async def main():
        def on_window(self, e):
            print(e)

        c = await Connection(auto_reconnect=True).connect()

        workspaces = await c.get_workspaces()

        c.on(Event.WINDOW, on_window)

        await c.main()

    asyncio.get_event_loop().run_until_complete(main())

Contributing
------------

Development happens on `Github <https://github.com/altdesktop/i3ipc-python>`__. Please feel free to report bugs, request features or add examples by submitting a pull request.

License
-------

This work is available under a BSD-3-Clause license (see LICENSE).

Copyright © 2015, Tony Crisci

All rights reserved.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/altdesktop/i3ipc-python",
    "name": "i3ipc",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.4.0",
    "maintainer_email": "",
    "keywords": "i3 i3wm extensions add-ons",
    "author": "Tony Crisci",
    "author_email": "tony@dubstepdish.com",
    "download_url": "https://files.pythonhosted.org/packages/61/f3/dfab70c888d85d3e933ff4d6b351aaed0ae137a29c896e03e364de3bec94/i3ipc-2.2.1.tar.gz",
    "platform": "",
    "description": "\ni3ipc-python\n============\n\nAn improved Python library to control `i3wm <http://i3wm.org>`__ and `sway <https://swaywm.org/>`__.\n\nAbout\n-----\n\ni3's interprocess communication (or `ipc <http://i3wm.org/docs/ipc.html>`__) is the interface i3wm uses to receive `commands <http://i3wm.org/docs/userguide.html#_list_of_commands>`__ from client applications such as ``i3-msg``. It also features a publish/subscribe mechanism for notifying interested parties of window manager events.\n\ni3ipc-python is a Python library for controlling the window manager.  This project is intended to be useful for general scripting, and for applications that interact with the window manager like status line generators, notification daemons, and window pagers.\n\nIf you have an idea for a script to extend i3wm, you can add your script to the `examples folder <https://github.com/acrisci/i3ipc-python/tree/master/examples>`__.\n\nFor details on how to use the library, see the `reference documentation <https://i3ipc-python.readthedocs.io/en/latest/>`__.\n\nInstallation\n------------\n\ni3ipc is on `PyPI <https://pypi.python.org/pypi/i3ipc>`__.\n\n``pip3 install i3ipc``\n\nExample\n-------\n\n.. code:: python3\n\n    from i3ipc import Connection, Event\n\n    # Create the Connection object that can be used to send commands and subscribe\n    # to events.\n    i3 = Connection()\n\n    # Print the name of the focused window\n    focused = i3.get_tree().find_focused()\n    print('Focused window %s is on workspace %s' %\n          (focused.name, focused.workspace().name))\n\n    # Query the ipc for outputs. The result is a list that represents the parsed\n    # reply of a command like `i3-msg -t get_outputs`.\n    outputs = i3.get_outputs()\n\n    print('Active outputs:')\n\n    for output in filter(lambda o: o.active, outputs):\n        print(output.name)\n\n    # Send a command to be executed synchronously.\n    i3.command('focus left')\n\n    # Take all fullscreen windows out of fullscreen\n    for container in i3.get_tree().find_fullscreen():\n        container.command('fullscreen')\n\n    # Print the names of all the containers in the tree\n    root = i3.get_tree()\n    print(root.name)\n    for con in root:\n        print(con.name)\n\n    # Define a callback to be called when you switch workspaces.\n    def on_workspace_focus(self, e):\n        # The first parameter is the connection to the ipc and the second is an object\n        # with the data of the event sent from i3.\n        if e.current:\n            print('Windows on this workspace:')\n            for w in e.current.leaves():\n                print(w.name)\n\n    # Dynamically name your workspaces after the current window class\n    def on_window_focus(i3, e):\n        focused = i3.get_tree().find_focused()\n        ws_name = \"%s:%s\" % (focused.workspace().num, focused.window_class)\n        i3.command('rename workspace to \"%s\"' % ws_name)\n\n    # Subscribe to events\n    i3.on(Event.WORKSPACE_FOCUS, on_workspace_focus)\n    i3.on(Event.WINDOW_FOCUS, on_window_focus)\n\n    # Start the main loop and wait for events to come in.\n    i3.main()\n\nAsyncio Support\n---------------\n\nSupport for asyncio is included in the ``i3ipc.aio`` package. The interface is similar to the blocking interface but the methods that interact with the socket are coroutines.\n\n.. code:: python3\n\n    from i3ipc.aio import Connection\n    from i3ipc import Event\n\n    import asyncio\n\n    async def main():\n        def on_window(self, e):\n            print(e)\n\n        c = await Connection(auto_reconnect=True).connect()\n\n        workspaces = await c.get_workspaces()\n\n        c.on(Event.WINDOW, on_window)\n\n        await c.main()\n\n    asyncio.get_event_loop().run_until_complete(main())\n\nContributing\n------------\n\nDevelopment happens on `Github <https://github.com/altdesktop/i3ipc-python>`__. Please feel free to report bugs, request features or add examples by submitting a pull request.\n\nLicense\n-------\n\nThis work is available under a BSD-3-Clause license (see LICENSE).\n\nCopyright \u00a9 2015, Tony Crisci\n\nAll rights reserved.\n\n\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "An improved Python library to control i3wm and sway",
    "version": "2.2.1",
    "project_urls": {
        "Homepage": "https://github.com/altdesktop/i3ipc-python"
    },
    "split_keywords": [
        "i3",
        "i3wm",
        "extensions",
        "add-ons"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "de30294b07ddeccb58855c890c3ef3a951c3b0c1e2d089666d548b6a9edc39fb",
                "md5": "3b937a28550450b9009bcabddb4ca505",
                "sha256": "c0b898223d50d42c90c818deb5033d1304c582755547dee7d15df3e3781bc690"
            },
            "downloads": -1,
            "filename": "i3ipc-2.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3b937a28550450b9009bcabddb4ca505",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.4.0",
            "size": 26591,
            "upload_time": "2020-04-05T17:25:07",
            "upload_time_iso_8601": "2020-04-05T17:25:07.338711Z",
            "url": "https://files.pythonhosted.org/packages/de/30/294b07ddeccb58855c890c3ef3a951c3b0c1e2d089666d548b6a9edc39fb/i3ipc-2.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "61f3dfab70c888d85d3e933ff4d6b351aaed0ae137a29c896e03e364de3bec94",
                "md5": "89dd6be829f5cf40ca6a963151c40709",
                "sha256": "e880d7d7147959ead5cb34764f08b97b41385b36eb8256e8af1ce163dbcccce8"
            },
            "downloads": -1,
            "filename": "i3ipc-2.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "89dd6be829f5cf40ca6a963151c40709",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.4.0",
            "size": 47760,
            "upload_time": "2020-04-05T17:25:08",
            "upload_time_iso_8601": "2020-04-05T17:25:08.666505Z",
            "url": "https://files.pythonhosted.org/packages/61/f3/dfab70c888d85d3e933ff4d6b351aaed0ae137a29c896e03e364de3bec94/i3ipc-2.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-04-05 17:25:08",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "altdesktop",
    "github_project": "i3ipc-python",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "i3ipc"
}
        
Elapsed time: 0.09332s