Skip to content

Init rust and python#1223

Merged
guibeira merged 5 commits intomainfrom
init-rust-and-python
Mar 4, 2026
Merged

Init rust and python#1223
guibeira merged 5 commits intomainfrom
init-rust-and-python

Conversation

@guibeira
Copy link
Contributor

@guibeira guibeira commented Mar 3, 2026

original PR:
iii-hq/sdk#31

Summary by CodeRabbit

  • New Features

    • Unified init() with InitOptions (including OpenTelemetry) that starts connections in the background; examples and helpers updated to use init() and explicit registration for streams.
  • Bug Fixes / Reliability

    • init() now reports a clear runtime error when no async runtime is present.
  • Behavior / Examples

    • Example defaults: metrics exporter set to memory; event module renamed to queue module and adapter updated to queue Redis adapter.
  • Breaking Changes

    • Direct constructor usage removed — migrate to init().

guibeira added 3 commits March 3, 2026 17:30
Introduces a top-level init(address, options) function that creates an
III client and auto-starts its connection task, matching the existing
Node SDK pattern. Updates examples to use init() instead of manual
III::new + connect.
Aligns the main SDK README with the new init() convenience function
for Python and Rust.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 3, 2026

📝 Walkthrough

Walkthrough

Python and Rust SDKs replace direct III construction with a new init(address, InitOptions) API that returns an III instance and starts connection work in the background; examples, tests, docs, and example app code updated to use InitOptions and injected III instances.

Changes

Cohort / File(s) Summary
Python SDK Core API
sdk/packages/python/iii/src/iii/__init__.py, sdk/packages/python/iii/src/iii/iii.py
Added public init(address, options) exported in __all__ that creates an III and schedules connect() on the running asyncio loop; InitOptions.otel now accepts OtelConfig or dict.
Rust SDK Core API
sdk/packages/rust/iii/src/lib.rs, sdk/packages/rust/iii/src/error.rs
Added public InitOptions and init(address, InitOptions) -> Result<III, IIIError> which spawns a background connect task; added IIIError::Runtime(String); OTEL config applied behind feature flag.
Python Example App & Modules
sdk/packages/python/iii-example/src/main.py, .../src/hooks.py, .../src/state.py, .../src/stream.py, .../src/iii.py
Refactored example to accept injected III instances (constructor/param injection), removed module-level iii singletons, added register_streams(iii) and adjusted setup to call init(...) and pass iii into uses.
Python Example Config
sdk/packages/python/iii-example/config.yaml
Config updates: OtelModule.metrics_exporter default changed to memory; modules::event::EventModule renamed to modules::queue::QueueModule; adapter class updated accordingly.
Examples & Docs
sdk/README.md, sdk/packages/python/iii/README.md, sdk/packages/rust/iii/README.md, sdk/packages/rust/iii-example/src/main.rs
Updated README and example code to use init(..., InitOptions) (including OTEL options); Rust example replaced III::new + config + connect() with single init(...) call.
Tests
sdk/packages/python/iii/tests/test_init_api.py, sdk/packages/rust/iii/tests/init_api.rs
Added tests validating init behavior: schedules connect on event loop/runtime, errors when no runtime present, and consumes OTEL configuration (Rust test conditional on feature).

Sequence Diagram(s)

sequenceDiagram
    participant App as Application
    participant Init as init(address, InitOptions)
    participant III as III Instance
    participant Runtime as Async Runtime
    participant Conn as Background Connect Task

    App->>Init: call init(address, InitOptions)
    Init->>III: create III (apply metadata/otel)
    Init->>Runtime: schedule/spawn connect() task
    Init-->>App: return III instance
    Runtime->>Conn: run connect task
    Conn->>III: iii.connect()
    Conn-->>Runtime: log result / finish
    App->>III: register functions / make calls
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • ytallo

Poem

🐰 A tiny hop, a clever tweak,
Init wakes clients, quiet and sleek,
Options folded, loops set right,
Background hum through day and night,
Old ctor naps — new paths we seek.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Init rust and python' is vague and does not clearly summarize the main changes. While it references two languages, it lacks specificity about what initialization changes are being made. Revise the title to be more specific and descriptive. For example: 'Replace direct client instantiation with init function for Rust and Python SDKs' or 'Add init() function and InitOptions type to replace direct III constructor usage'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch init-rust-and-python

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
sdk/packages/rust/iii/tests/init_api.rs (1)

23-39: Test name overstates what is asserted.

Line 23 says OTEL is applied before auto-connect, but the test only verifies successful init + registration. Consider either renaming the test or asserting observable OTEL side effects.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@sdk/packages/rust/iii/tests/init_api.rs` around lines 23 - 39, The test name
init_applies_otel_config_before_auto_connect overclaims the behavior; either
rename the test to accurately reflect what's asserted (e.g.,
init_applies_otel_config_and_allows_registration or
init_sets_otel_config_and_registers) or add an assertion that verifies an OTEL
side effect (for example, inspect the configured Otel/tracer provider after
calling init, or assert that no auto-connection occurred before registration) —
update the test function init_applies_otel_config_before_auto_connect and its
use of InitOptions/OtelConfig and the created client (client.register_function)
accordingly to implement the chosen fix.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@sdk/packages/python/iii-example/src/state.py`:
- Line 3: The State.set method uses iii.call() without initializing iii, causing
a NameError; fix it by calling get_iii() and assigning it to iii at the start of
State.set (matching the pattern used in other methods), i.e., add iii =
get_iii() before any use of iii.call() so State.set initializes the III client
before invoking its call method.

---

Nitpick comments:
In `@sdk/packages/rust/iii/tests/init_api.rs`:
- Around line 23-39: The test name init_applies_otel_config_before_auto_connect
overclaims the behavior; either rename the test to accurately reflect what's
asserted (e.g., init_applies_otel_config_and_allows_registration or
init_sets_otel_config_and_registers) or add an assertion that verifies an OTEL
side effect (for example, inspect the configured Otel/tracer provider after
calling init, or assert that no auto-connection occurred before registration) —
update the test function init_applies_otel_config_before_auto_connect and its
use of InitOptions/OtelConfig and the created client (client.register_function)
accordingly to implement the chosen fix.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f658c67 and e8a6073.

⛔ Files ignored due to path filters (2)
  • sdk/packages/python/iii-example/uv.lock is excluded by !**/*.lock
  • sdk/packages/rust/iii-example/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (16)
  • sdk/README.md
  • sdk/packages/python/iii-example/config.yaml
  • sdk/packages/python/iii-example/src/hooks.py
  • sdk/packages/python/iii-example/src/iii.py
  • sdk/packages/python/iii-example/src/main.py
  • sdk/packages/python/iii-example/src/state.py
  • sdk/packages/python/iii-example/src/stream.py
  • sdk/packages/python/iii/README.md
  • sdk/packages/python/iii/src/iii/__init__.py
  • sdk/packages/python/iii/src/iii/iii.py
  • sdk/packages/python/iii/tests/test_init_api.py
  • sdk/packages/rust/iii-example/src/main.rs
  • sdk/packages/rust/iii/README.md
  • sdk/packages/rust/iii/src/error.rs
  • sdk/packages/rust/iii/src/lib.rs
  • sdk/packages/rust/iii/tests/init_api.rs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
sdk/packages/python/iii-example/src/main.py (2)

13-14: Consider using specific types instead of Any for module-level variables.

Using Any for state and streams loses type safety and IDE support. Consider using the actual types with None union:

♻️ Suggested type improvement
-state: Any = None
-streams: Any = None
+from .state import State
+from .stream import StreamClient
+
+state: State | None = None
+streams: StreamClient | None = None

Note: If circular imports are a concern with top-level imports, you could use TYPE_CHECKING:

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from .state import State
    from .stream import StreamClient

state: "State | None" = None
streams: "StreamClient | None" = None
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@sdk/packages/python/iii-example/src/main.py` around lines 13 - 14, Replace
the module-level Any annotations for state and streams with their actual types
to restore type safety: use the concrete classes (e.g. State and StreamClient)
in the annotations for state and streams respectively, or if importing them at
top-level causes circular imports, use typing.TYPE_CHECKING and
forward-reference string annotations (e.g. "State | None", "StreamClient |
None") so the variables are typed as optional instances rather than Any; update
the declarations for state and streams accordingly and import types only under
TYPE_CHECKING if needed.

22-22: Add type annotation for iii parameter.

For consistency with the rest of the codebase where iii: III is explicitly typed, consider adding the type annotation here.

♻️ Suggested fix
+from iii import III
+
-def _setup(iii) -> None:
+def _setup(iii: III) -> None:

Note: You'll need to add III to the import on line 11.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@sdk/packages/python/iii-example/src/main.py` at line 22, The _setup function
is missing a type annotation for its parameter; update the signature of _setup
to declare the parameter as iii: III (i.e., def _setup(iii: III) -> None:) and
add III to the imports mentioned on line 11 so the type is available for
annotation; ensure you import III from the same module used elsewhere in the
file to keep types consistent with the codebase.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@sdk/packages/python/iii-example/src/main.py`:
- Around line 13-14: Replace the module-level Any annotations for state and
streams with their actual types to restore type safety: use the concrete classes
(e.g. State and StreamClient) in the annotations for state and streams
respectively, or if importing them at top-level causes circular imports, use
typing.TYPE_CHECKING and forward-reference string annotations (e.g. "State |
None", "StreamClient | None") so the variables are typed as optional instances
rather than Any; update the declarations for state and streams accordingly and
import types only under TYPE_CHECKING if needed.
- Line 22: The _setup function is missing a type annotation for its parameter;
update the signature of _setup to declare the parameter as iii: III (i.e., def
_setup(iii: III) -> None:) and add III to the imports mentioned on line 11 so
the type is available for annotation; ensure you import III from the same module
used elsewhere in the file to keep types consistent with the codebase.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between adcece0 and 990494c.

📒 Files selected for processing (5)
  • sdk/packages/python/iii-example/src/hooks.py
  • sdk/packages/python/iii-example/src/iii.py
  • sdk/packages/python/iii-example/src/main.py
  • sdk/packages/python/iii-example/src/state.py
  • sdk/packages/python/iii-example/src/stream.py
💤 Files with no reviewable changes (1)
  • sdk/packages/python/iii-example/src/iii.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • sdk/packages/python/iii-example/src/hooks.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants