Skip to content

fix: transitive dependency conflict with Klyne - #25

Merged
psincraian merged 1 commit into
mainfrom
claude/fix-klyne-dependency-conflict-018A8XSs5TNeHa2VG4KBPYm5
Nov 19, 2025
Merged

psincraian merged 1 commit into
mainfrom
claude/fix-klyne-dependency-conflict-018A8XSs5TNeHa2VG4KBPYm5

Conversation

@psincraian

Copy link
Copy Markdown
Owner

Fixed dependency conflict where library A could not use Klyne if its dependency (library B) already used Klyne. The SDK now supports multiple concurrent clients in the same Python process.

Changes

Architecture:

  • Replaced single global _client with _clients dictionary (keyed by project name)
  • Added _default_client for backward compatibility with module-level API
  • Each project gets its own isolated KlyneClient instance

API Enhancements:

  • init() now returns KlyneClient instance for direct use
  • Module-level functions (track, flush, etc.) still work for backward compatibility
  • Libraries can use either module-level API or instance-based API

Auto-initialization:

  • Removed automatic self-analytics initialization on import
  • Self-analytics now opt-in via KLYNE_SELF_ANALYTICS=1 environment variable
  • Prevents unwanted side effects and background threads on import

Testing

  • All existing integration tests pass (backward compatibility verified)
  • Added comprehensive test suite in test_multiple_clients.py
  • Tested nested library scenario (Library A depends on Library B)

Breaking Changes

None - fully backward compatible. Existing code continues to work unchanged.

Migration Guide

For libraries that want isolation from other Klyne users:

# Old style (still works)
import klyne
klyne.init(api_key="...", project="my-lib")
klyne.track("event")

# New style (recommended for libraries)
import klyne
client = klyne.init(api_key="...", project="my-lib")
client.track("event")

Fixes issue where only one library per process could use Klyne analytics.

Fixed dependency conflict where library A could not use Klyne if its
dependency (library B) already used Klyne. The SDK now supports multiple
concurrent clients in the same Python process.

## Changes

**Architecture:**
- Replaced single global `_client` with `_clients` dictionary (keyed by project name)
- Added `_default_client` for backward compatibility with module-level API
- Each project gets its own isolated KlyneClient instance

**API Enhancements:**
- `init()` now returns KlyneClient instance for direct use
- Module-level functions (track, flush, etc.) still work for backward compatibility
- Libraries can use either module-level API or instance-based API

**Auto-initialization:**
- Removed automatic self-analytics initialization on import
- Self-analytics now opt-in via KLYNE_SELF_ANALYTICS=1 environment variable
- Prevents unwanted side effects and background threads on import

## Testing

- All existing integration tests pass (backward compatibility verified)
- Added comprehensive test suite in test_multiple_clients.py
- Tested nested library scenario (Library A depends on Library B)

## Breaking Changes

None - fully backward compatible. Existing code continues to work unchanged.

## Migration Guide

For libraries that want isolation from other Klyne users:

```python
# Old style (still works)
import klyne
klyne.init(api_key="...", project="my-lib")
klyne.track("event")

# New style (recommended for libraries)
import klyne
client = klyne.init(api_key="...", project="my-lib")
client.track("event")
```

Fixes issue where only one library per process could use Klyne analytics.
@psincraian
psincraian merged commit bef2fd1 into main Nov 19, 2025
2 checks passed
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