requests-unixsocket
===================
.. image:: https://badge.fury.io/py/requests-unixsocket.svg
:target: https://badge.fury.io/py/requests-unixsocket
:alt: Latest Version on PyPI
.. image:: https://github.com/msabramo/requests-unixsocket/actions/workflows/tests.yml/badge.svg
:target: https://github.com/msabramo/requests-unixsocket/actions/workflows/tests.yml
Use `requests <http://docs.python-requests.org/>`_ to talk HTTP via a UNIX domain socket
Usage
-----
Explicit
++++++++
You can use it by instantiating a special ``Session`` object:
.. code-block:: python
import json
import requests_unixsocket
session = requests_unixsocket.Session()
r = session.get('http+unix://%2Fvar%2Frun%2Fdocker.sock/info')
registry_config = r.json()['RegistryConfig']
print(json.dumps(registry_config, indent=4))
Implicit (monkeypatching)
+++++++++++++++++++++++++
Monkeypatching allows you to use the functionality in this module, while making
minimal changes to your code. Note that in the above example we had to
instantiate a special ``requests_unixsocket.Session`` object and call the
``get`` method on that object. Calling ``requests.get(url)`` (the easiest way
to use requests and probably very common), would not work. But we can make it
work by doing monkeypatching.
You can monkeypatch globally:
.. code-block:: python
import requests_unixsocket
requests_unixsocket.monkeypatch()
r = requests.get('http+unix://%2Fvar%2Frun%2Fdocker.sock/info')
assert r.status_code == 200
or you can do it temporarily using a context manager:
.. code-block:: python
import requests_unixsocket
with requests_unixsocket.monkeypatch():
r = requests.get('http+unix://%2Fvar%2Frun%2Fdocker.sock/info')
assert r.status_code == 200
Abstract namespace sockets
++++++++++++++++++++++++++
To connect to an `abstract namespace
socket <https://utcc.utoronto.ca/~cks/space/blog/python/AbstractUnixSocketsAndPeercred>`_
(Linux only), prefix the name with a NULL byte (i.e.: `\0`) - e.g.:
.. code-block:: python
import requests_unixsocket
session = requests_unixsocket.Session()
res = session.get('http+unix://\0test_socket/get')
print(res.text)
For an example program that illustrates this, see
``examples/abstract_namespace.py`` in the git repo. Since abstract namespace
sockets are specific to Linux, the program will only work on Linux.
See also
--------
- https://github.com/httpie/httpie-unixsocket - a plugin for `HTTPie <https://httpie.org/>`_ that allows you to interact with UNIX domain sockets
Raw data
{
"_id": null,
"home_page": "https://github.com/msabramo/requests-unixsocket",
"name": "requests-unixsocket",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Marc Abramowitz",
"author_email": "marc@marc-abramowitz.com",
"download_url": "https://files.pythonhosted.org/packages/c3/ea/0fb87f844d8a35ff0dcc8b941e1a9ffc9eb46588ac9e4267b9d9804354eb/requests-unixsocket-0.3.0.tar.gz",
"platform": "",
"description": "requests-unixsocket\n===================\n\n.. image:: https://badge.fury.io/py/requests-unixsocket.svg\n :target: https://badge.fury.io/py/requests-unixsocket\n :alt: Latest Version on PyPI\n \n.. image:: https://github.com/msabramo/requests-unixsocket/actions/workflows/tests.yml/badge.svg\n :target: https://github.com/msabramo/requests-unixsocket/actions/workflows/tests.yml\n\nUse `requests <http://docs.python-requests.org/>`_ to talk HTTP via a UNIX domain socket\n\nUsage\n-----\n\nExplicit\n++++++++\n\nYou can use it by instantiating a special ``Session`` object:\n\n.. code-block:: python\n\n import json\n\n import requests_unixsocket\n\n session = requests_unixsocket.Session()\n\n r = session.get('http+unix://%2Fvar%2Frun%2Fdocker.sock/info')\n registry_config = r.json()['RegistryConfig']\n print(json.dumps(registry_config, indent=4))\n\n\nImplicit (monkeypatching)\n+++++++++++++++++++++++++\n\nMonkeypatching allows you to use the functionality in this module, while making\nminimal changes to your code. Note that in the above example we had to\ninstantiate a special ``requests_unixsocket.Session`` object and call the\n``get`` method on that object. Calling ``requests.get(url)`` (the easiest way\nto use requests and probably very common), would not work. But we can make it\nwork by doing monkeypatching.\n\nYou can monkeypatch globally:\n\n.. code-block:: python\n\n import requests_unixsocket\n\n requests_unixsocket.monkeypatch()\n\n r = requests.get('http+unix://%2Fvar%2Frun%2Fdocker.sock/info')\n assert r.status_code == 200\n\nor you can do it temporarily using a context manager:\n\n.. code-block:: python\n\n import requests_unixsocket\n\n with requests_unixsocket.monkeypatch():\n r = requests.get('http+unix://%2Fvar%2Frun%2Fdocker.sock/info')\n assert r.status_code == 200\n\n\nAbstract namespace sockets\n++++++++++++++++++++++++++\n\nTo connect to an `abstract namespace\nsocket <https://utcc.utoronto.ca/~cks/space/blog/python/AbstractUnixSocketsAndPeercred>`_\n(Linux only), prefix the name with a NULL byte (i.e.: `\\0`) - e.g.:\n\n.. code-block:: python\n\n import requests_unixsocket\n\n session = requests_unixsocket.Session()\n res = session.get('http+unix://\\0test_socket/get')\n print(res.text)\n\nFor an example program that illustrates this, see\n``examples/abstract_namespace.py`` in the git repo. Since abstract namespace\nsockets are specific to Linux, the program will only work on Linux.\n\n\nSee also\n--------\n\n- https://github.com/httpie/httpie-unixsocket - a plugin for `HTTPie <https://httpie.org/>`_ that allows you to interact with UNIX domain sockets\n\n\n\n",
"bugtrack_url": null,
"license": "Apache-2",
"summary": "Use requests to talk HTTP via a UNIX domain socket",
"version": "0.3.0",
"project_urls": {
"Homepage": "https://github.com/msabramo/requests-unixsocket"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b363e9e81d5e7370d46f08407c37399b507725125587b01fff46b4da5ddd3a4a",
"md5": "c682ab2e29da99f90635fed23882d973",
"sha256": "c685c680f0809e1b2955339b1e5afc3c0022b3066f4f7eb343f43a6065fc0e5d"
},
"downloads": -1,
"filename": "requests_unixsocket-0.3.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "c682ab2e29da99f90635fed23882d973",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 11835,
"upload_time": "2021-12-24T01:38:16",
"upload_time_iso_8601": "2021-12-24T01:38:16.028150Z",
"url": "https://files.pythonhosted.org/packages/b3/63/e9e81d5e7370d46f08407c37399b507725125587b01fff46b4da5ddd3a4a/requests_unixsocket-0.3.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c3ea0fb87f844d8a35ff0dcc8b941e1a9ffc9eb46588ac9e4267b9d9804354eb",
"md5": "2da31f8d76fb563bc3fd6d59a2fb260a",
"sha256": "28304283ea9357d45fff58ad5b11e47708cfbf5806817aa59b2a363228ee971e"
},
"downloads": -1,
"filename": "requests-unixsocket-0.3.0.tar.gz",
"has_sig": false,
"md5_digest": "2da31f8d76fb563bc3fd6d59a2fb260a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 14478,
"upload_time": "2021-12-24T01:38:17",
"upload_time_iso_8601": "2021-12-24T01:38:17.790320Z",
"url": "https://files.pythonhosted.org/packages/c3/ea/0fb87f844d8a35ff0dcc8b941e1a9ffc9eb46588ac9e4267b9d9804354eb/requests-unixsocket-0.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2021-12-24 01:38:17",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "msabramo",
"github_project": "requests-unixsocket",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "requests",
"specs": [
[
">=",
"1.1"
]
]
}
],
"tox": true,
"lcname": "requests-unixsocket"
}