rb_utils
rb_utils is a collection of utilities reused across the backend.
Modules / Functions
1) rb_utils.parser
snake_to_camel(s: str) -> str: Converts a snake_case string to CamelCasecamel_to_snake(s: str) -> str: Converts a CamelCase string to snake_caset_to_dict(obj: Any) -> Any: Recursively converts nested objects (FlatBuffer T, dict/list/tuple/set, bytes, numpy arrays) into Python built-in types_normalize_filter(filter_: Any) -> dict: NormalizesNone/dict/JSON stringinto a common dictto_json(obj: Any) -> str: Serializes the result oft_to_dictto a JSON stringto_iso(val: str | datetime) -> str: Returns an ISO string for a datetime, or the string unchanged
Example:
from rb_utils.parser import t_to_dict, to_json
payload_dict = t_to_dict(obj_payload)
payload_json = to_json(obj_payload)
2) rb_utils.flow_manager
safe_eval_expr(expr, variables=None, get_global_variable=None) -> Any: Safely evaluates an expression under restricted AST rules_pick_target_loop(func, provided) -> asyncio.AbstractEventLoop | None: Selects the loop on which to run the callablecall_with_matching_args(func, **provided) -> Any: Calls a function with only the arguments matching its signature (works for both sync and async)eval_value(value, variables=None, get_global_variable=None) -> Any: Recursively evaluates strings/lists/tuples/dictsmake_builtins_allow_most() -> dict: Builds a builtins dict excluding dangerous builtins
Example:
from rb_utils.flow_manager import eval_value
value = eval_value("a + 10", variables={"local": {"a": 5}, "global": {}})
# value == 15
3) rb_utils.asyncio_helper
spawn(coro, *, name=None, log_ex=True): Creates a task on the current loop and logs its completion/exceptions_ensure_private_loop() -> asyncio.AbstractEventLoop: Ensures a dedicated background loop existsfire_and_log(coro, *, name=None, loop=None): Safely runs on the current loop, an external loop, or the dedicated loop_attach_done_logging(fut_or_task, *, name=None): Attaches a callback that logs exceptions when a Future/Task completes
Example:
from rb_utils.asyncio_helper import fire_and_log
fire_and_log(socket_client.emit("muscat/program/log", {"msg": "hello"}), name="program-log")
4) rb_utils.service_exception
class ServiceException(Exception):- Fields:
message: str,status_code: int | None __str__(): Outputs in the formmessage (status=...)to_dict(): Returns{message, status_code}
- Fields:
Example:
from rb_utils.service_exception import ServiceException
raise ServiceException("invalid request", status_code=400)
5) rb_utils.date
is_valid_date(d): Validates adate/str/int(timestamp)timestamp_ms_to_seconds(timestamp, tz=UTC): Normalizes a ms/seconds timestamp to secondsis_has_time(s: str): Determines whether a string contains time informationparse_date_with_time(mode, d, tz=UTC): Converts a date/string/timestamp to a timezone-aware datetimeensure_datetime(dt, tz): Coerces adate | datetimeinto a datetime in the given tz_tz(tz_name): Looks up a timezone from the cacheconvert_dt(local, in_tz, out_tz): Converts a datetime/date from the input tz to the output tzget_current_dt_yyyymmddhhmmss(tz): Returns the current time as aYYYYMMDDHHMMSSstring
Example:
from rb_utils.date import parse_date_with_time
from datetime import UTC
dt = parse_date_with_time("start", "2026-02-25", tz=UTC)
6) rb_utils.file
content_disposition_header(filename) -> str: Builds aContent-Dispositionheader for downloadssanitize_filename(name, default="export.csv", max_name_len=100) -> str: Removes OS-forbidden characters and limits lengthget_env_path() -> Path | None: Searches for a.envfile relative to the working location
Example:
from rb_utils.file import sanitize_filename
safe_name = sanitize_filename("../../report?.csv")
7) rb_utils.env
env_get(key, default=None, start=None): Looks up a value fromos.environfirst, then the nearest.env.development→.env, in that orderload_env(start=None, override=False): Loads the nearest env files intoos.environiter_env_paths(start=None): Returns the env files that will actually be read, in priority orderparse_env_file(path): Parses an env file into a dict
Example:
In new code, you don't need load_env() to read a single value directly.
from rb_utils.env import env_get
username = env_get("MONGO_USERNAME")
password = env_get("MONGO_PASSWORD")
host = env_get("MONGO_HOST", "127.0.0.1")
If existing code uses os.getenv(...) heavily, load once at process startup.
import os
from rb_utils.env import load_env
load_env()
username = os.getenv("MONGO_USERNAME")
password = os.getenv("MONGO_PASSWORD")
Default priority:
- The
.env.developmentclosest to the current location .envin the same directory.env.developmentin the parent directory.envin the parent directory
In other words, in a development environment .env.development overrides values in .env.
Production builds do not copy .env.development, so only .env applies.
If you need a different suffix, specify it explicitly:
env_get("KEY", env_files=(".env.local", ".env.development", ".env"))
8) rb_utils.pagination
class PageInfo(TypedDict): Page response metadata type (mode/page/pages/limit/total/sort/order)class LogsResponse(TypedDict): Log list response type (items,pageInfo)
9) rb_utils.helper
ManipulateZenohResHelper(obj): Function intended as a utility for fixing up Zenoh response objects
Caution:
- The current implementation uses
.hasAttr/.setaccess instead of dict handling and raisesValueErrorimmediately, so verify its behavior before use.
Common Usage Patterns
- Flattening FlatBuffer/SDK responses:
t_to_dict - Evaluating dynamic Flow step arguments:
eval_value,safe_eval_expr - Async fire-and-forget + exception logging:
fire_and_log - Common service-layer exception:
ServiceException - File downloads / filename sanitization:
content_disposition_header,sanitize_filename
General Notes
- The
flow_managerevaluator only executes allowed operations/functions. - Timezone conversion functions require an explicit IANA tz string such as
Asia/Seoul.
Metadata
Release files for rainbow-rb-utils 0.10.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rainbow_rb_utils-0.10.6.tar.gz | 28.7 kB | Without provenance | Details for rainbow_rb_utils-0.10.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rainbow_rb_utils-0.10.6-py3-none-any.whl | Python 3 | none | any | Details for rainbow_rb_utils-0.10.6-py3-none-any.whl |
Total release size: 59.1 kB
Release files / rainbow_rb_utils-0.10.6.tar.gz
| Download URL | rainbow_rb_utils-0.10.6.tar.gz |
|---|---|
| Size | 28.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
de39c3623ee4e29c4d99b96395f1abac6943cd87cc4ba231789b657ce8081e18
|
|
BLAKE2b-256 checksum How to use checksums |
01d62722f0d0f066d7b0ff3aa21de718d6a600be6ac6cd0afcfff02e92a7a66d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / rainbow_rb_utils-0.10.6-py3-none-any.whl
| Download URL | rainbow_rb_utils-0.10.6-py3-none-any.whl |
|---|---|
| Size | 30.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2147d21035265ddb4531f46e55cf7b7caf454e5dc06107e8cfc6fcd05e7bef0a
|
|
BLAKE2b-256 checksum How to use checksums |
82784ed4d53c5a699b4a4914a9118d71d5dc4d20fb7ae2df6bd0ce03ac910681
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Security for rainbow-rb-utils 0.10.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.