Env
abb_rws_client_python_rw6.core.env
Environment configuration loader for abb_rws_client_python_rw6.
Author: Clement RACINET
Resolves and loads a .env file into :data:os.environ using
:mod:python-dotenv (already a runtime dependency). The lookup walks
up the directory tree from a given starting point, so it works correctly
regardless of the current working directory or script nesting depth.
This module is part of the library's public API. Any application or script can
call :func:load_env to bootstrap the environment before instantiating
:class:~abb_rws_client_python_rw6.RWSClient.
Environment variables recognised by :class:~abb_rws_client_python_rw6.RWSClient:
- RWS_HOST : Controller IP or hostname (required if not passed explicitly).
- RWS_USER : RWS username (default: "Default User").
- RWS_PASSWORD : RWS password (default: "robotics").
- RWS_PORT : HTTP port as integer string (default: "80").
- RWS_TIMEOUT : HTTP timeout in seconds as float string (default: no timeout).
Set to a number (e.g. "30") to limit request duration.
- RWS_LOG_LEVEL: Logging level for :func:~abb_rws_client_python_rw6.configure_logging
(default: "WARNING").
get_env_float(key, default)
Read a float environment variable with a fallback default.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Example
timeout = get_env_float("RWS_TIMEOUT", 10.0)
Source code in abb_rws_client_python_rw6/core/env.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
get_env_float_or_none(key, default)
Read a float-or-None environment variable with a fallback default.
Accepts "none", "inf", "infinite", "infinity"
(case-insensitive) as special string values mapping to None
(no timeout). When the variable is absent or empty, default is
returned as-is.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Example
timeout = get_env_float_or_none("RWS_TIMEOUT", None) timeout is None # → no timeout True
Source code in abb_rws_client_python_rw6/core/env.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
get_env_int(key, default)
Read an integer environment variable with a fallback default.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Example
port = get_env_int("RWS_PORT", 80)
Source code in abb_rws_client_python_rw6/core/env.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
get_env_str(key, default)
Read a string environment variable with a fallback default.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Example
host = get_env_str("RWS_HOST", "192.168.125.1")
Source code in abb_rws_client_python_rw6/core/env.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
load_env(env_path=None, *, override=False)
Locate and load a .env file into :data:os.environ.
Uses :func:dotenv.load_dotenv under the hood (python-dotenv).
When env_path is None, the function walks up the directory tree
starting from the caller's file location (via :data:Path.cwd)
until it finds a .env file or reaches the filesystem root.
Already-set variables are never overwritten unless override is
True — safe to call multiple times.
| Parameters: |
|
|---|
| Returns: |
|
|---|
| Raises: |
|
|---|
Example
Automatic discovery from current working directory::
from abb_rws_client_python_rw6import load_env
load_env()
Explicit path::
from abb_rws_client_python_rw6import load_env
from pathlib import Path
load_env(Path("/etc/myrobot/.env"))
Override existing variables::
from abb_rws_client_python_rw6import load_env
load_env(override=True)
Source code in abb_rws_client_python_rw6/core/env.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |