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": "parsys-requests-unixsocket",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Marc Abramowitz",
"author_email": "marc@marc-abramowitz.com",
"download_url": "",
"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.1",
"project_urls": {
"Homepage": "https://github.com/msabramo/requests-unixsocket"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "57772c1437c77cd1bfa96b98cdbee3f62af47050866633fec10f78603651be27",
"md5": "6c3f8db2a753e88f436e020d7995f54c",
"sha256": "e40ace8ddb9e7549b98db11fb1a930d6648af0ece0330650aa9253cbc8cecf02"
},
"downloads": -1,
"filename": "parsys_requests_unixsocket-0.3.1-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "6c3f8db2a753e88f436e020d7995f54c",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 12078,
"upload_time": "2023-07-06T17:17:19",
"upload_time_iso_8601": "2023-07-06T17:17:19.352203Z",
"url": "https://files.pythonhosted.org/packages/57/77/2c1437c77cd1bfa96b98cdbee3f62af47050866633fec10f78603651be27/parsys_requests_unixsocket-0.3.1-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-06 17:17:19",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "msabramo",
"github_project": "requests-unixsocket",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"tox": true,
"lcname": "parsys-requests-unixsocket"
}