wsproto


Namewsproto JSON
Version 1.2.0 PyPI version JSON
download
home_pagehttps://github.com/python-hyper/wsproto/
SummaryWebSockets state-machine based protocol implementation
upload_time2022-08-23 19:58:21
maintainer
docs_urlNone
authorBenno Rice
requires_python>=3.7.0
licenseMIT License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ========================================================
Pure Python, pure state-machine WebSocket implementation
========================================================

.. image:: https://github.com/python-hyper/wsproto/workflows/CI/badge.svg
    :target: https://github.com/python-hyper/wsproto/actions
    :alt: Build Status
.. image:: https://codecov.io/gh/python-hyper/wsproto/branch/main/graph/badge.svg
    :target: https://codecov.io/gh/python-hyper/wsproto
    :alt: Code Coverage
.. image:: https://readthedocs.org/projects/wsproto/badge/?version=latest
    :target: https://wsproto.readthedocs.io/en/latest/
    :alt: Documentation Status
.. image:: https://img.shields.io/badge/chat-join_now-brightgreen.svg
    :target: https://gitter.im/python-hyper/community
    :alt: Chat community


This repository contains a pure-Python implementation of a WebSocket protocol
stack. It's written from the ground up to be embeddable in whatever program you
choose to use, ensuring that you can communicate via WebSockets, as defined in
`RFC6455 <https://tools.ietf.org/html/rfc6455>`_, regardless of your programming
paradigm.

This repository does not provide a parsing layer, a network layer, or any rules
about concurrency. Instead, it's a purely in-memory solution, defined in terms
of data actions and WebSocket frames. RFC6455 and Compression Extensions for
WebSocket via `RFC7692 <https://tools.ietf.org/html/rfc7692>`_ are fully
supported.

wsproto supports Python 3.6.1 or higher.

To install it, just run:

.. code-block:: console

    $ pip install wsproto


Usage
=====

Let's assume you have some form of network socket available. wsproto client
connections automatically generate a HTTP request to initiate the WebSocket
handshake. To create a WebSocket client connection:

.. code-block:: python

  from wsproto import WSConnection, ConnectionType
  from wsproto.events import Request

  ws = WSConnection(ConnectionType.CLIENT)
  ws.send(Request(host='echo.websocket.org', target='/'))

To create a WebSocket server connection:

.. code-block:: python

  from wsproto.connection import WSConnection, ConnectionType

  ws = WSConnection(ConnectionType.SERVER)

Every time you send a message, or call a ping, or simply if you receive incoming
data, wsproto might respond with some outgoing data that you have to send:

.. code-block:: python

  some_socket.send(ws.bytes_to_send())

Both connection types need to receive incoming data:

.. code-block:: python

  ws.receive_data(some_byte_string_of_data)

And wsproto will issue events if the data contains any WebSocket messages or state changes:

.. code-block:: python

  for event in ws.events():
      if isinstance(event, Request):
          # only client connections get this event
          ws.send(AcceptConnection())
      elif isinstance(event, CloseConnection):
          # guess nobody wants to talk to us any more...
      elif isinstance(event, TextMessage):
          print('We got text!', event.data)
      elif isinstance(event, BytesMessage):
          print('We got bytes!', event.data)

Take a look at our docs for a `full list of events
<https://wsproto.readthedocs.io/en/latest/api.html#events>`!

Testing
=======

It passes the autobahn test suite completely and strictly in both client and
server modes and using permessage-deflate.

If you want to run the compliance tests, go into the compliance directory and
then to test client mode, in one shell run the Autobahn test server:

.. code-block:: console

    $ wstest -m fuzzingserver -s ws-fuzzingserver.json

And in another shell run the test client:

.. code-block:: console

    $ python test_client.py

And to test server mode, run the test server:

.. code-block:: console

    $ python test_server.py

And in another shell run the Autobahn test client:

.. code-block:: console

    $ wstest -m fuzzingclient -s ws-fuzzingclient.json


Documentation
=============

Documentation is available at https://wsproto.readthedocs.io/en/latest/.

Contributing
============

``wsproto`` welcomes contributions from anyone! Unlike many other projects we
are happy to accept cosmetic contributions and small contributions, in addition
to large feature requests and changes.

Before you contribute (either by opening an issue or filing a pull request),
please `read the contribution guidelines`_.

.. _read the contribution guidelines: http://python-hyper.org/en/latest/contributing.html

License
=======

``wsproto`` is made available under the MIT License. For more details, see the
``LICENSE`` file in the repository.

Authors
=======

``wsproto`` was created by @jeamland, and is maintained by the python-hyper
community.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/python-hyper/wsproto/",
    "name": "wsproto",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Benno Rice",
    "author_email": "benno@jeamland.net",
    "download_url": "https://files.pythonhosted.org/packages/c9/4a/44d3c295350d776427904d73c189e10aeae66d7f555bb2feee16d1e4ba5a/wsproto-1.2.0.tar.gz",
    "platform": null,
    "description": "========================================================\nPure Python, pure state-machine WebSocket implementation\n========================================================\n\n.. image:: https://github.com/python-hyper/wsproto/workflows/CI/badge.svg\n    :target: https://github.com/python-hyper/wsproto/actions\n    :alt: Build Status\n.. image:: https://codecov.io/gh/python-hyper/wsproto/branch/main/graph/badge.svg\n    :target: https://codecov.io/gh/python-hyper/wsproto\n    :alt: Code Coverage\n.. image:: https://readthedocs.org/projects/wsproto/badge/?version=latest\n    :target: https://wsproto.readthedocs.io/en/latest/\n    :alt: Documentation Status\n.. image:: https://img.shields.io/badge/chat-join_now-brightgreen.svg\n    :target: https://gitter.im/python-hyper/community\n    :alt: Chat community\n\n\nThis repository contains a pure-Python implementation of a WebSocket protocol\nstack. It's written from the ground up to be embeddable in whatever program you\nchoose to use, ensuring that you can communicate via WebSockets, as defined in\n`RFC6455 <https://tools.ietf.org/html/rfc6455>`_, regardless of your programming\nparadigm.\n\nThis repository does not provide a parsing layer, a network layer, or any rules\nabout concurrency. Instead, it's a purely in-memory solution, defined in terms\nof data actions and WebSocket frames. RFC6455 and Compression Extensions for\nWebSocket via `RFC7692 <https://tools.ietf.org/html/rfc7692>`_ are fully\nsupported.\n\nwsproto supports Python 3.6.1 or higher.\n\nTo install it, just run:\n\n.. code-block:: console\n\n    $ pip install wsproto\n\n\nUsage\n=====\n\nLet's assume you have some form of network socket available. wsproto client\nconnections automatically generate a HTTP request to initiate the WebSocket\nhandshake. To create a WebSocket client connection:\n\n.. code-block:: python\n\n  from wsproto import WSConnection, ConnectionType\n  from wsproto.events import Request\n\n  ws = WSConnection(ConnectionType.CLIENT)\n  ws.send(Request(host='echo.websocket.org', target='/'))\n\nTo create a WebSocket server connection:\n\n.. code-block:: python\n\n  from wsproto.connection import WSConnection, ConnectionType\n\n  ws = WSConnection(ConnectionType.SERVER)\n\nEvery time you send a message, or call a ping, or simply if you receive incoming\ndata, wsproto might respond with some outgoing data that you have to send:\n\n.. code-block:: python\n\n  some_socket.send(ws.bytes_to_send())\n\nBoth connection types need to receive incoming data:\n\n.. code-block:: python\n\n  ws.receive_data(some_byte_string_of_data)\n\nAnd wsproto will issue events if the data contains any WebSocket messages or state changes:\n\n.. code-block:: python\n\n  for event in ws.events():\n      if isinstance(event, Request):\n          # only client connections get this event\n          ws.send(AcceptConnection())\n      elif isinstance(event, CloseConnection):\n          # guess nobody wants to talk to us any more...\n      elif isinstance(event, TextMessage):\n          print('We got text!', event.data)\n      elif isinstance(event, BytesMessage):\n          print('We got bytes!', event.data)\n\nTake a look at our docs for a `full list of events\n<https://wsproto.readthedocs.io/en/latest/api.html#events>`!\n\nTesting\n=======\n\nIt passes the autobahn test suite completely and strictly in both client and\nserver modes and using permessage-deflate.\n\nIf you want to run the compliance tests, go into the compliance directory and\nthen to test client mode, in one shell run the Autobahn test server:\n\n.. code-block:: console\n\n    $ wstest -m fuzzingserver -s ws-fuzzingserver.json\n\nAnd in another shell run the test client:\n\n.. code-block:: console\n\n    $ python test_client.py\n\nAnd to test server mode, run the test server:\n\n.. code-block:: console\n\n    $ python test_server.py\n\nAnd in another shell run the Autobahn test client:\n\n.. code-block:: console\n\n    $ wstest -m fuzzingclient -s ws-fuzzingclient.json\n\n\nDocumentation\n=============\n\nDocumentation is available at https://wsproto.readthedocs.io/en/latest/.\n\nContributing\n============\n\n``wsproto`` welcomes contributions from anyone! Unlike many other projects we\nare happy to accept cosmetic contributions and small contributions, in addition\nto large feature requests and changes.\n\nBefore you contribute (either by opening an issue or filing a pull request),\nplease `read the contribution guidelines`_.\n\n.. _read the contribution guidelines: http://python-hyper.org/en/latest/contributing.html\n\nLicense\n=======\n\n``wsproto`` is made available under the MIT License. For more details, see the\n``LICENSE`` file in the repository.\n\nAuthors\n=======\n\n``wsproto`` was created by @jeamland, and is maintained by the python-hyper\ncommunity.\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "WebSockets state-machine based protocol implementation",
    "version": "1.2.0",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "8e51f07d98a3a89ffc284233c80c5815",
                "sha256": "b9acddd652b585d75b20477888c56642fdade28bdfd3579aa24a4d2c037dd736"
            },
            "downloads": -1,
            "filename": "wsproto-1.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8e51f07d98a3a89ffc284233c80c5815",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7.0",
            "size": 24226,
            "upload_time": "2022-08-23T19:58:19",
            "upload_time_iso_8601": "2022-08-23T19:58:19.960674Z",
            "url": "https://files.pythonhosted.org/packages/78/58/e860788190eba3bcce367f74d29c4675466ce8dddfba85f7827588416f01/wsproto-1.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "f64973434117e23d2079460ed64b05c3",
                "sha256": "ad565f26ecb92588a3e43bc3d96164de84cd9902482b130d0ddbaa9664a85065"
            },
            "downloads": -1,
            "filename": "wsproto-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "f64973434117e23d2079460ed64b05c3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7.0",
            "size": 53425,
            "upload_time": "2022-08-23T19:58:21",
            "upload_time_iso_8601": "2022-08-23T19:58:21.447641Z",
            "url": "https://files.pythonhosted.org/packages/c9/4a/44d3c295350d776427904d73c189e10aeae66d7f555bb2feee16d1e4ba5a/wsproto-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-08-23 19:58:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "python-hyper",
    "github_project": "wsproto",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "wsproto"
}
        
Elapsed time: 0.01208s