pynghttp2


Namepynghttp2 JSON
Version 0.3.2 PyPI version JSON
download
home_pagehttps://github.com/kahlertl/pynghttp2
SummaryAsyncio bindings for libnghttp2 based on ctypes
upload_time2023-06-01 00:54:26
maintainer
docs_urlNone
authorLucas Kahlert
requires_python
licenseMIT
keywords http/2 nghttp2 bindings asyncio ctypes
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            =========
pynghttp2
=========

.. image:: https://badge.fury.io/py/pynghttp2.svg
    :target: https://badge.fury.io/py/pynghttp2
    :alt: PyPi Version

.. image:: https://codecov.io/gh/kahlertl/pynghttp2/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/kahlertl/pynghttp2
    :alt: Code Coverage

.. image:: https://readthedocs.org/projects/pynghttp2/badge/?version=latest
    :target: http://pynghttp2.readthedocs.io/en/latest/?badge=latest
    :alt: Documentation Status

pynghttp2 are simple asyncio Python bindings based on ctypes for the nghttp2_
library. The only thing you need is a ``libnghttp2`` version on your system.

On Debian-based systems you can install nghttp2 simply via apt:

.. code:: bash

    apt-get install libnghttp2-14

The project was created in the context of a student work for an HTTP/2 protocol
gateway in the µPCN_ project - an implementation of Delay-tolerant Networking
(DTN) protocols.


Installation
============

.. code:: bash

    pip install pynghttp2


Examples
========

High-Level API
--------------

.. code:: python

    from pynghttp2 import http2

    # GET request
    resp = await http2.get('http://localhost:64602/ping')

    content = await resp.text()
    assert content == 'pong'

    # POST request
    message = b"Lorem ipsum dolorem"
    resp = await http2.post('http://localhost:64602/echo', data=message)
    echo = await resp.read()
    assert echo == message


Client Session
--------------

.. code:: python

    from pynghttp2 import ClientSession

    # Multiplex two requests
    async with ClientSession(host='localhost', port=64602) as session:
        stream1 = session.get('http://localhost:64602/stream')
        stream2 = session.get('http://localhost:64602/stream')

        await asyncio.gather(stream1.read(), stream2.read())


Server Session
--------------

.. code:: python

    import asyncio
    from pynghttp2 import ServerSession

    async def handle_request(req):
        """Echo the request body"""
        msg = await req.read()
        await req.response(200, data=msg)

    with ServerSession(host='localhost', port=8080) as session:
        while True:
            # Wait for next incoming request
            req = await session

            # Handle each request in its own task to be able to multiplex
            # multiple requests and responses
            asyncio.ensure_future(handle_request(req))


.. _nghttp2: https://nghttp2.org/
.. _µPCN: https://upcn.eu/

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/kahlertl/pynghttp2",
    "name": "pynghttp2",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "HTTP/2 nghttp2 bindings asyncio ctypes",
    "author": "Lucas Kahlert",
    "author_email": "lucas.kahlert@square-src.de",
    "download_url": "https://files.pythonhosted.org/packages/ac/45/4e13a6d7bef018f10493c7370ca8c9710cf882017881f79fe6043df5f5a8/pynghttp2-0.3.2.tar.gz",
    "platform": "POSIX/Unix",
    "description": "=========\npynghttp2\n=========\n\n.. image:: https://badge.fury.io/py/pynghttp2.svg\n    :target: https://badge.fury.io/py/pynghttp2\n    :alt: PyPi Version\n\n.. image:: https://codecov.io/gh/kahlertl/pynghttp2/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/kahlertl/pynghttp2\n    :alt: Code Coverage\n\n.. image:: https://readthedocs.org/projects/pynghttp2/badge/?version=latest\n    :target: http://pynghttp2.readthedocs.io/en/latest/?badge=latest\n    :alt: Documentation Status\n\npynghttp2 are simple asyncio Python bindings based on ctypes for the nghttp2_\nlibrary. The only thing you need is a ``libnghttp2`` version on your system.\n\nOn Debian-based systems you can install nghttp2 simply via apt:\n\n.. code:: bash\n\n    apt-get install libnghttp2-14\n\nThe project was created in the context of a student work for an HTTP/2 protocol\ngateway in the \u00b5PCN_ project - an implementation of Delay-tolerant Networking\n(DTN) protocols.\n\n\nInstallation\n============\n\n.. code:: bash\n\n    pip install pynghttp2\n\n\nExamples\n========\n\nHigh-Level API\n--------------\n\n.. code:: python\n\n    from pynghttp2 import http2\n\n    # GET request\n    resp = await http2.get('http://localhost:64602/ping')\n\n    content = await resp.text()\n    assert content == 'pong'\n\n    # POST request\n    message = b\"Lorem ipsum dolorem\"\n    resp = await http2.post('http://localhost:64602/echo', data=message)\n    echo = await resp.read()\n    assert echo == message\n\n\nClient Session\n--------------\n\n.. code:: python\n\n    from pynghttp2 import ClientSession\n\n    # Multiplex two requests\n    async with ClientSession(host='localhost', port=64602) as session:\n        stream1 = session.get('http://localhost:64602/stream')\n        stream2 = session.get('http://localhost:64602/stream')\n\n        await asyncio.gather(stream1.read(), stream2.read())\n\n\nServer Session\n--------------\n\n.. code:: python\n\n    import asyncio\n    from pynghttp2 import ServerSession\n\n    async def handle_request(req):\n        \"\"\"Echo the request body\"\"\"\n        msg = await req.read()\n        await req.response(200, data=msg)\n\n    with ServerSession(host='localhost', port=8080) as session:\n        while True:\n            # Wait for next incoming request\n            req = await session\n\n            # Handle each request in its own task to be able to multiplex\n            # multiple requests and responses\n            asyncio.ensure_future(handle_request(req))\n\n\n.. _nghttp2: https://nghttp2.org/\n.. _\u00b5PCN: https://upcn.eu/\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Asyncio bindings for libnghttp2 based on ctypes",
    "version": "0.3.2",
    "project_urls": {
        "Bug Tracker": "https://github.com/kahlertl/pynghttp2/issues",
        "Documentation": "https://pynghttp2.readthedocs.io/",
        "Homepage": "https://github.com/kahlertl/pynghttp2",
        "Source Code": "https://github.com/kahlertl/pynghttp2/"
    },
    "split_keywords": [
        "http/2",
        "nghttp2",
        "bindings",
        "asyncio",
        "ctypes"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f951340b717a7f2555c63d1e4a938f435e0fd30bb09b7cfc16c135f9be65d799",
                "md5": "32e092936e1e87d75ed358baf1003d6a",
                "sha256": "0051bb45c549a4ce4d5bbe8cbde237d50bf84c3366a445c9bc0b27c5e7871937"
            },
            "downloads": -1,
            "filename": "pynghttp2-0.3.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "32e092936e1e87d75ed358baf1003d6a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 25250,
            "upload_time": "2023-06-01T00:54:23",
            "upload_time_iso_8601": "2023-06-01T00:54:23.679779Z",
            "url": "https://files.pythonhosted.org/packages/f9/51/340b717a7f2555c63d1e4a938f435e0fd30bb09b7cfc16c135f9be65d799/pynghttp2-0.3.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ac454e13a6d7bef018f10493c7370ca8c9710cf882017881f79fe6043df5f5a8",
                "md5": "1b5384907ef8d85514615e3dc316fdd1",
                "sha256": "42263801c3ab55d5aca188af9fa269fd68eefa5fdb43cb22f7686055b6de7247"
            },
            "downloads": -1,
            "filename": "pynghttp2-0.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "1b5384907ef8d85514615e3dc316fdd1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 24030,
            "upload_time": "2023-06-01T00:54:26",
            "upload_time_iso_8601": "2023-06-01T00:54:26.074313Z",
            "url": "https://files.pythonhosted.org/packages/ac/45/4e13a6d7bef018f10493c7370ca8c9710cf882017881f79fe6043df5f5a8/pynghttp2-0.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-01 00:54:26",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kahlertl",
    "github_project": "pynghttp2",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "pynghttp2"
}
        
Elapsed time: 2.16525s