claudestream 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. claudestream-0.1.0/.claude/settings.json +3 -0
  2. claudestream-0.1.0/.github/workflows/ci.yml +21 -0
  3. claudestream-0.1.0/.github/workflows/publish.yml +18 -0
  4. claudestream-0.1.0/.gitignore +15 -0
  5. claudestream-0.1.0/.rlsbl/bases/.claude/settings.json +3 -0
  6. claudestream-0.1.0/.rlsbl/bases/.github/workflows/ci.yml +21 -0
  7. claudestream-0.1.0/.rlsbl/bases/.github/workflows/publish.yml +18 -0
  8. claudestream-0.1.0/.rlsbl/bases/.gitignore +15 -0
  9. claudestream-0.1.0/.rlsbl/bases/.rlsbl/hooks/post-release.sh +8 -0
  10. claudestream-0.1.0/.rlsbl/bases/.rlsbl/hooks/pre-release.sh +41 -0
  11. claudestream-0.1.0/.rlsbl/bases/CHANGELOG.md +5 -0
  12. claudestream-0.1.0/.rlsbl/bases/CLAUDE.md +20 -0
  13. claudestream-0.1.0/.rlsbl/bases/LICENSE +21 -0
  14. claudestream-0.1.0/.rlsbl/config.json +5 -0
  15. claudestream-0.1.0/.rlsbl/hashes.json +11 -0
  16. claudestream-0.1.0/.rlsbl/hooks/post-release.sh +8 -0
  17. claudestream-0.1.0/.rlsbl/hooks/pre-release.sh +41 -0
  18. claudestream-0.1.0/.rlsbl/version +1 -0
  19. claudestream-0.1.0/CHANGELOG.md +11 -0
  20. claudestream-0.1.0/CLAUDE.md +20 -0
  21. claudestream-0.1.0/LICENSE +21 -0
  22. claudestream-0.1.0/PKG-INFO +11 -0
  23. claudestream-0.1.0/claudestream/__init__.py +120 -0
  24. claudestream-0.1.0/claudestream/_async_session.py +290 -0
  25. claudestream-0.1.0/claudestream/_cli.py +208 -0
  26. claudestream-0.1.0/claudestream/_process.py +240 -0
  27. claudestream-0.1.0/claudestream/_protocol.py +328 -0
  28. claudestream-0.1.0/claudestream/_sync_session.py +188 -0
  29. claudestream-0.1.0/claudestream/events.py +260 -0
  30. claudestream-0.1.0/claudestream/messages.py +105 -0
  31. claudestream-0.1.0/claudestream/policy.py +152 -0
  32. claudestream-0.1.0/docs/index.md +105 -0
  33. claudestream-0.1.0/pyproject.toml +22 -0
  34. claudestream-0.1.0/scripts/.gitkeep +0 -0
  35. claudestream-0.1.0/selfdoc.json +6 -0
  36. claudestream-0.1.0/tests/__init__.py +0 -0
  37. claudestream-0.1.0/tests/conftest.py +1 -0
  38. claudestream-0.1.0/tests/test_events.py +331 -0
  39. claudestream-0.1.0/tests/test_messages.py +71 -0
  40. claudestream-0.1.0/tests/test_policy.py +97 -0
  41. claudestream-0.1.0/tests/test_process.py +78 -0
  42. claudestream-0.1.0/tests/test_protocol_io.py +106 -0
  43. claudestream-0.1.0/todo/.done/.gitkeep +0 -0
  44. claudestream-0.1.0/todo/.gitkeep +0 -0
  45. claudestream-0.1.0/todo/claudewheel-integration.md +14 -0
  46. claudestream-0.1.0/todo/mcp-server-registration.md +16 -0
  47. claudestream-0.1.0/todo/pydantic-models.md +20 -0
  48. claudestream-0.1.0/todo/session-resumption.md +15 -0
  49. claudestream-0.1.0/uv.lock +105 -0
@@ -0,0 +1,3 @@
1
+ {
2
+ "hooks": {}
3
+ }
@@ -0,0 +1,21 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ # requires-python: >= {{pypi.minRequiredPython}}
15
+ python-version: ["3.12", "3.13", "3.14"]
16
+ steps:
17
+ - uses: actions/checkout@v6
18
+ - uses: astral-sh/setup-uv@v7
19
+ - run: uv python install ${{ matrix.python-version }}
20
+ - run: uv sync
21
+ - run: uv run python -c "import claudestream"
@@ -0,0 +1,18 @@
1
+ name: Publish
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ permissions:
8
+ contents: read
9
+ id-token: write
10
+
11
+ jobs:
12
+ publish:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v6
16
+ - uses: astral-sh/setup-uv@v7
17
+ - run: uv build
18
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,15 @@
1
+ node_modules/
2
+ __pycache__/
3
+ *.pyc
4
+ *.log
5
+ .DS_Store
6
+ coverage/
7
+ dist/
8
+ *.egg-info/
9
+ .rlsbl-notes-*.tmp
10
+ .rlsbl/lock
11
+ .credentials.json
12
+ .*-cache.json
13
+ .env
14
+ .env.local
15
+ *.local-only
@@ -0,0 +1,3 @@
1
+ {
2
+ "hooks": {}
3
+ }
@@ -0,0 +1,21 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ # requires-python: >= {{pypi.minRequiredPython}}
15
+ python-version: ["3.12", "3.13", "3.14"]
16
+ steps:
17
+ - uses: actions/checkout@v6
18
+ - uses: astral-sh/setup-uv@v7
19
+ - run: uv python install ${{ matrix.python-version }}
20
+ - run: uv sync
21
+ - run: uv run python -c "import claudestream"
@@ -0,0 +1,18 @@
1
+ name: Publish
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ permissions:
8
+ contents: read
9
+ id-token: write
10
+
11
+ jobs:
12
+ publish:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v6
16
+ - uses: astral-sh/setup-uv@v7
17
+ - run: uv build
18
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,15 @@
1
+ node_modules/
2
+ __pycache__/
3
+ *.pyc
4
+ *.log
5
+ .DS_Store
6
+ coverage/
7
+ dist/
8
+ *.egg-info/
9
+ .rlsbl-notes-*.tmp
10
+ .rlsbl/lock
11
+ .credentials.json
12
+ .*-cache.json
13
+ .env
14
+ .env.local
15
+ *.local-only
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ # Post-release hook. Runs after a successful release (non-fatal).
3
+ # Environment: RLSBL_VERSION is set to the released version.
4
+ # Customize this for your project (e.g., local install, deploy, notify).
5
+
6
+ set -euo pipefail
7
+
8
+ echo "Post-release: v$RLSBL_VERSION"
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env bash
2
+ # Pre-release validation hook.
3
+ # Runs before rlsbl creates a release. Exit non-zero to abort.
4
+ # Detects project type and runs appropriate checks automatically.
5
+
6
+ set -euo pipefail
7
+
8
+ echo "Running pre-release checks..."
9
+
10
+ if [ -f go.mod ]; then
11
+ echo " Go: vet + build + test"
12
+ go vet ./...
13
+ go build ./...
14
+ go test ./... -race -short -count=1
15
+ fi
16
+
17
+ if [ -f pyproject.toml ]; then
18
+ echo " Python: pytest"
19
+ if command -v uv &>/dev/null; then
20
+ uv run pytest
21
+ elif command -v pytest &>/dev/null; then
22
+ pytest
23
+ fi
24
+ fi
25
+
26
+ if [ -f package.json ] && node -e "process.exit(require('./package.json').scripts?.test ? 0 : 1)" 2>/dev/null; then
27
+ echo " npm: test"
28
+ npm test
29
+ fi
30
+
31
+ # Library lint (monorepo only)
32
+ if command -v rlsbl &>/dev/null; then
33
+ if rlsbl doctor --check library-lint 2>/dev/null; then
34
+ :
35
+ else
36
+ echo " Library lint check failed"
37
+ exit 1
38
+ fi
39
+ fi
40
+
41
+ echo "Pre-release checks passed."
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ - Initial release
@@ -0,0 +1,20 @@
1
+ # claudestream
2
+
3
+ ## Release workflow
4
+
5
+ This project uses [rlsbl](https://github.com/smm-h/rlsbl) for release orchestration.
6
+
7
+ - Update CHANGELOG.md with a `## X.Y.Z` entry describing changes
8
+ - Run `rlsbl release [patch|minor|major]` to bump version and create a GitHub Release
9
+ - CI handles publishing automatically via the publish workflow
10
+ - Never publish manually — always use `rlsbl release`
11
+ - Configure Trusted Publishing on pypi.org for automated PyPI releases
12
+ - Use `rlsbl release --dry-run` to preview a release without making changes
13
+
14
+ ## Conventions
15
+
16
+ - No tokens or secrets in command-line arguments (use env vars or config files)
17
+ - All file writes to shared state should be atomic (write to tmp, then rename)
18
+ - External calls (APIs, CLI tools) must have timeouts and graceful fallbacks
19
+ - Use `npm link` (npm) or `uv pip install -e .` (Python) for local development
20
+ - CI runs smoke tests on every push; manual testing for UI/UX changes
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 smm-h
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,5 @@
1
+ {
2
+ "targets": [
3
+ "pypi"
4
+ ]
5
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ ".github/workflows/ci.yml": "4328950c6097cc32e53ea8f750a3dde1b8593a480b9007b4548cd740fc0d56e6",
3
+ ".github/workflows/publish.yml": "55e2dba57d17218c2887ba90051d31aee15067cc0b69c8adebc2deab07aef76b",
4
+ "CHANGELOG.md": "7a6ec46141007c18090a0ff325e2dd68cd51588c4e0b5af7b580365e5eaaca85",
5
+ ".gitignore": "c89d76c6c43e7f0897b3472a15b7c0103e0be5b3a04c2b44e585fa48bdcda2bb",
6
+ "LICENSE": "e958892abc1dd5d991fca6d528e695d335f25773d373d2e0be5f4a9507d8f8d5",
7
+ "CLAUDE.md": "7d5b9e24e36e74f0116b97fc3510382c1fddec9bd611a1230db4330e161f5ac6",
8
+ ".rlsbl/hooks/pre-release.sh": "c3579d31ae56b8415d7dfead8758ec488fe9ffceea0e2592c1fe1d0ac8ee858c",
9
+ ".rlsbl/hooks/post-release.sh": "b455f8511e0b2655509ecf5dcb0ab7da5bb7c961f47910ff8e00cab5bd51f833",
10
+ ".claude/settings.json": "78922a784ee78e9e50587e93628cd3b9d4dfbe49087adc4514e6781cea38cbb9"
11
+ }
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ # Post-release hook. Runs after a successful release (non-fatal).
3
+ # Environment: RLSBL_VERSION is set to the released version.
4
+ # Customize this for your project (e.g., local install, deploy, notify).
5
+
6
+ set -euo pipefail
7
+
8
+ echo "Post-release: v$RLSBL_VERSION"
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env bash
2
+ # Pre-release validation hook.
3
+ # Runs before rlsbl creates a release. Exit non-zero to abort.
4
+ # Detects project type and runs appropriate checks automatically.
5
+
6
+ set -euo pipefail
7
+
8
+ echo "Running pre-release checks..."
9
+
10
+ if [ -f go.mod ]; then
11
+ echo " Go: vet + build + test"
12
+ go vet ./...
13
+ go build ./...
14
+ go test ./... -race -short -count=1
15
+ fi
16
+
17
+ if [ -f pyproject.toml ]; then
18
+ echo " Python: pytest"
19
+ if command -v uv &>/dev/null; then
20
+ uv run pytest
21
+ elif command -v pytest &>/dev/null; then
22
+ pytest
23
+ fi
24
+ fi
25
+
26
+ if [ -f package.json ] && node -e "process.exit(require('./package.json').scripts?.test ? 0 : 1)" 2>/dev/null; then
27
+ echo " npm: test"
28
+ npm test
29
+ fi
30
+
31
+ # Library lint (monorepo only)
32
+ if command -v rlsbl &>/dev/null; then
33
+ if rlsbl doctor --check library-lint 2>/dev/null; then
34
+ :
35
+ else
36
+ echo " Library lint check failed"
37
+ exit 1
38
+ fi
39
+ fi
40
+
41
+ echo "Pre-release checks passed."
@@ -0,0 +1 @@
1
+ 0.22.1
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ - Async and sync session APIs (`AsyncSession`, `SyncSession`) for multi-turn conversations with Claude Code
6
+ - One-shot `print_prompt()` convenience function for simple use cases
7
+ - Typed event models for all Claude Code stream-json event types
8
+ - Real-time streaming token support via `StreamDelta` events
9
+ - Configurable permission policy system (allow_all, deny_all, allow_builtins, allow_list, custom callbacks)
10
+ - CLI with 4 commands: `send`, `stream`, `events`, `repl`
11
+ - Subprocess lifecycle management with graceful shutdown
@@ -0,0 +1,20 @@
1
+ # claudestream
2
+
3
+ ## Release workflow
4
+
5
+ This project uses [rlsbl](https://github.com/smm-h/rlsbl) for release orchestration.
6
+
7
+ - Update CHANGELOG.md with a `## X.Y.Z` entry describing changes
8
+ - Run `rlsbl release [patch|minor|major]` to bump version and create a GitHub Release
9
+ - CI handles publishing automatically via the publish workflow
10
+ - Never publish manually — always use `rlsbl release`
11
+ - Configure Trusted Publishing on pypi.org for automated PyPI releases
12
+ - Use `rlsbl release --dry-run` to preview a release without making changes
13
+
14
+ ## Conventions
15
+
16
+ - No tokens or secrets in command-line arguments (use env vars or config files)
17
+ - All file writes to shared state should be atomic (write to tmp, then rename)
18
+ - External calls (APIs, CLI tools) must have timeouts and graceful fallbacks
19
+ - Use `npm link` (npm) or `uv pip install -e .` (Python) for local development
20
+ - CI runs smoke tests on every push; manual testing for UI/UX changes
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 smm-h
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.4
2
+ Name: claudestream
3
+ Version: 0.1.0
4
+ Summary: A Python library and CLI for streaming Claude Code's JSON protocol
5
+ Author-email: SMM-H <lisa.codi@veliu.com>
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Keywords: rlsbl
9
+ Requires-Python: >=3.11
10
+ Requires-Dist: selfdoc
11
+ Requires-Dist: strictcli
@@ -0,0 +1,120 @@
1
+ """A Python library and CLI for streaming Claude Code's JSON protocol."""
2
+
3
+ from claudestream._async_session import AsyncSession, ClaudeStreamError
4
+ from claudestream._sync_session import SyncSession
5
+ from claudestream.events import (
6
+ AssistantMessage,
7
+ AssistantText,
8
+ ApiRetry,
9
+ CompactBoundary,
10
+ ContentBlock,
11
+ Event,
12
+ McpRequest,
13
+ PermissionRequest,
14
+ RateLimit,
15
+ Result,
16
+ StreamDelta,
17
+ SystemInit,
18
+ TextBlock,
19
+ Thinking,
20
+ ThinkingBlock,
21
+ ToolResult,
22
+ ToolResultBlock,
23
+ ToolResultMessage,
24
+ ToolUse,
25
+ ToolUseBlock,
26
+ UnknownEvent,
27
+ Usage,
28
+ )
29
+ from claudestream.policy import (
30
+ Allow,
31
+ AllowAllPolicy,
32
+ AllowBuiltinsPolicy,
33
+ AllowListPolicy,
34
+ CallbackPolicy,
35
+ Deny,
36
+ Policy,
37
+ allow_all,
38
+ allow_builtins,
39
+ allow_list,
40
+ callback,
41
+ deny_all,
42
+ )
43
+
44
+ __all__ = [
45
+ # Sessions
46
+ "AsyncSession",
47
+ "SyncSession",
48
+ "ClaudeStreamError",
49
+ # Events
50
+ "Event",
51
+ "SystemInit",
52
+ "ApiRetry",
53
+ "CompactBoundary",
54
+ "AssistantMessage",
55
+ "AssistantText",
56
+ "ToolResultMessage",
57
+ "ToolUse",
58
+ "ToolResult",
59
+ "Thinking",
60
+ "StreamDelta",
61
+ "Result",
62
+ "RateLimit",
63
+ "PermissionRequest",
64
+ "McpRequest",
65
+ "UnknownEvent",
66
+ # Content blocks
67
+ "TextBlock",
68
+ "ToolUseBlock",
69
+ "ThinkingBlock",
70
+ "ToolResultBlock",
71
+ "ContentBlock",
72
+ "Usage",
73
+ # Policy
74
+ "Policy",
75
+ "Allow",
76
+ "Deny",
77
+ "AllowAllPolicy",
78
+ "AllowBuiltinsPolicy",
79
+ "AllowListPolicy",
80
+ "CallbackPolicy",
81
+ "allow_all",
82
+ "deny_all",
83
+ "allow_builtins",
84
+ "allow_list",
85
+ "callback",
86
+ # Convenience
87
+ "print_prompt",
88
+ ]
89
+
90
+
91
+ def print_prompt(
92
+ prompt: str,
93
+ *,
94
+ model: str | None = None,
95
+ cwd: str | None = None,
96
+ binary: str | None = None,
97
+ policy: Policy | None = None,
98
+ system_prompt: str | None = None,
99
+ extra_args: list[str] | None = None,
100
+ env: dict[str, str] | None = None,
101
+ ) -> str:
102
+ """One-shot convenience: send a prompt and return the full response text.
103
+
104
+ Creates a SyncSession, sends one message, collects AssistantText events,
105
+ and returns the concatenated text. For claudewheel integration.
106
+ """
107
+ parts: list[str] = []
108
+ with SyncSession(
109
+ model=model,
110
+ cwd=cwd,
111
+ binary=binary,
112
+ policy=policy,
113
+ system_prompt=system_prompt,
114
+ extra_args=extra_args,
115
+ env=env,
116
+ ) as session:
117
+ for event in session.send(prompt):
118
+ if isinstance(event, AssistantText):
119
+ parts.append(event.text)
120
+ return "".join(parts)