RETIRED, further work has moved to Debian project infrastructure
Go to file
Marc Abramowitz 0dd4da72d7 examples/docker-info.py: Make executable (#33) 2017-02-21 11:12:21 -08:00
examples examples/docker-info.py: Make executable (#33) 2017-02-21 11:12:21 -08:00
requests_unixsocket Merge pull request #28 from RantyDave/master 2017-02-19 12:12:16 -08:00
.gitignore .gitignore: Add .vagrant 2017-02-19 15:35:32 -08:00
.travis.yml .travis.yml: Remove py36 2017-02-19 11:22:37 -08:00
LICENSE Initial commit 2014-11-25 08:07:00 -08:00
Makefile Add Makefile (#31) 2017-02-21 08:42:21 -08:00
README.rst Move examples to separate directory 2017-02-21 08:16:57 -08:00
Vagrantfile Vagrantfile: Add socat 2017-02-20 09:32:34 -08:00
pytest.ini Add pytest-pep8 2014-11-25 09:32:10 -08:00
requirements.txt Add urllib3 requirement. 2015-07-22 12:32:44 +02:00
setup.cfg Add support for Python 3.6 2017-02-19 10:52:46 -08:00
setup.py Yay, tests are passing 2014-11-25 08:31:58 -08:00
test-requirements.txt test-requirements.txt: Get rid of pytest warnings 2017-02-19 11:36:35 -08:00
tox.ini tox.ini: Add py26 back 2017-02-19 11:29:00 -08:00

README.rst

requests-unixsocket

Latest Version on PyPI

image

Use requests to talk HTTP via a UNIX domain socket

Usage

Explicit

You can use it by instantiating a special Session object:

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:

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:

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 (Linux only), prefix the name with a NULL byte (i.e.: 0) - e.g.:

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