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/parsys-telemedicine/requests-unixsocket",
"name": "parsys-requests-unixsocket",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Marc Abramowitz",
"author_email": "marc@marc-abramowitz.com",
"download_url": "https://files.pythonhosted.org/packages/76/62/94b98694c8e6ce93cb153ec3f7694984b29191596977b8499ba8c4189ead/parsys_requests_unixsocket-0.3.2.tar.gz",
"platform": null,
"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",
"bugtrack_url": null,
"license": "Apache-2",
"summary": "Use requests to talk HTTP via a UNIX domain socket",
"version": "0.3.2",
"project_urls": {
"Homepage": "https://github.com/parsys-telemedicine/requests-unixsocket"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "16882cadf61a862d42d8de79a8928ae068a06e038a7047ccba845eb22f54a37a",
"md5": "4c4fd16ba8a3a1fdf5c88e71e3c30648",
"sha256": "5c4fef9e30d1861df87872189f23bb31550754a337b493d00eeafd2078783f9b"
},
"downloads": -1,
"filename": "parsys_requests_unixsocket-0.3.2-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "4c4fd16ba8a3a1fdf5c88e71e3c30648",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 12111,
"upload_time": "2024-05-28T14:25:23",
"upload_time_iso_8601": "2024-05-28T14:25:23.550279Z",
"url": "https://files.pythonhosted.org/packages/16/88/2cadf61a862d42d8de79a8928ae068a06e038a7047ccba845eb22f54a37a/parsys_requests_unixsocket-0.3.2-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "766294b98694c8e6ce93cb153ec3f7694984b29191596977b8499ba8c4189ead",
"md5": "33b354140ecc6546a01563110247b105",
"sha256": "27f6a2345e6ef8d618500f4eb50229584f67df1f16e72fa753b7c9b42c45214d"
},
"downloads": -1,
"filename": "parsys_requests_unixsocket-0.3.2.tar.gz",
"has_sig": false,
"md5_digest": "33b354140ecc6546a01563110247b105",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 13877,
"upload_time": "2024-05-28T14:25:25",
"upload_time_iso_8601": "2024-05-28T14:25:25.278994Z",
"url": "https://files.pythonhosted.org/packages/76/62/94b98694c8e6ce93cb153ec3f7694984b29191596977b8499ba8c4189ead/parsys_requests_unixsocket-0.3.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-28 14:25:25",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "parsys-telemedicine",
"github_project": "requests-unixsocket",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "requests",
"specs": [
[
"<",
"3.0"
],
[
">=",
"2.0"
]
]
},
{
"name": "urllib3",
"specs": [
[
"<",
"3.0"
],
[
">=",
"2.0"
]
]
}
],
"tox": true,
"lcname": "parsys-requests-unixsocket"
}