diff --git a/nomad/__init__.py b/nomad/__init__.py index 43437c5..55f0d0b 100644 --- a/nomad/__init__.py +++ b/nomad/__init__.py @@ -4,6 +4,8 @@ from typing import Optional, Union import requests +from urllib.parse import quote +from requests_unixsocket import Session from nomad import api @@ -67,6 +69,8 @@ def __init__( # pylint: disable=too-many-arguments self.secure = secure self.port = port self.address = address or os.getenv("NOMAD_ADDR", None) + if self.address and self.address.startswith("unix://"): + self.address = "http+unix://" + quote(self.address[7:], safe = "") self.user_agent = user_agent self.region = region or os.getenv("NOMAD_REGION", None) self.timeout = timeout @@ -75,6 +79,8 @@ def __init__( # pylint: disable=too-many-arguments self.verify = verify self.cert = cert if all(cert) else () self.session = session + if not self.session and self.address and self.address.startswith("http+unix://"): + self.session = Session() self.__namespace = namespace or os.getenv("NOMAD_NAMESPACE", None) self.requester_settings = { diff --git a/requirements.txt b/requirements.txt index 6e42168..c5c6223 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ requests==2.32.2 +requests-unixsocket==0.4.1 \ No newline at end of file diff --git a/setup.py b/setup.py index c44d07b..d94f5d0 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setuptools.setup( name='python-nomad', version='2.1.0', - install_requires=['requests'], + install_requires=['requests', 'requests-unixsocket'], packages=['nomad', 'nomad.api'], url='http://github.com/jrxfive/python-nomad', license='MIT',