Metadata-Version: 2.1
Name: pywpas
Version: 0.9.2
Summary: A python library to control wpa_supplicant via it's control socket.
Home-page: http://github.com/btimby/pywpas/
Author: Ben Timby
Author-email: btimby@gmail.com
Maintainer: Ben Timby
Maintainer-email: btimby@gmail.com
License: MIT
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries :: Python Modules
License-File: LICENSE

.. image:: https://coveralls.io/repos/github/btimby/pywpas/badge.svg?branch=master
    :target: https://coveralls.io/github/btimby/pywpas?branch=master

.. image:: https://github.com/btimby/pywpas/actions/workflows/ci.yml/badge.svg
    :target: https://github.com/btimby/pywpas/actions

.. image:: https://badge.fury.io/py/pywpas.svg
    :target: https://badge.fury.io/py/pywpas

pywpas
======

A python library to control wpa_supplicant via it's control socket.

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

``pip install pywpas``

Example
-------

.. code-block:: python

    import time
    import pywpas
    # sock_path below is the default and can be omitted.
    ctrl = pywpas.Control(sock_path='/var/run/wpa_supplicant)

    # You can get a list of interface names:
    interface_names = ctrl.interface_names()
    print(interface_names)

    # You can iterate over instances of the Interface class:
    for interface in ctrl.interfaces:
        print(interface.name)
    
    # You can get a specific Interface instance by name:
    interface = ctrl.interface(interface_names[0])
    print(interface.status())

    # You can scan for networks available on an interface:
    interface.scan()
    # You might wait a few seconds...
    time.sleep(5.0)
    scan_results = interface.results()

    for network in scan_results:
        print(network.ssid, network.signal_level)

    # You can connect to a network (implictly adds a profile):
    interface.connect(scan_results[0])
    # Write the network to the wpa_supplicant.conf file:
    interface.save_config()
    # Then disconnect...
    interface.disconnect()
    # and remove the network:
    interface.del_network(scan_results[0])
    interface.save_config()

    # You can also add a profile (without connecting):
    interface.add_network(scan_results[0])
    # And save it:
    interface.save_config()

    # You can define a network and connect to it:
    network = pywpas.Network(ssid='FOOBAR', ...)
    interface.connect(network)
    interface.disconnect()

    # There is a high-level scan function, it will invoke callback
    # with each unique network found during the scan timeout duration:
    scan = interface.background_scan(lambda network: print(network.ssid),
                                     timeout=30.0)
    time.sleep(5.0)
    scan.stop()

wpa_supplicant configuration
----------------------------

You must configure wpa_supplicant to open a control socket. Optionally you can
enable config file writing.

.. code-block:: bash

    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=nobody
    update_config=1

Event with an emtpy configuation (no networks) you can use this library to add
networks, connect to networks and save the profiles to the configuration file.

Development
-----------

To deploy to PyPI:

::

    git tag <version>
    git push --tags

CI will do the rest.

Tests and linting:

::

    make test
    make lint

