tokencap 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 (63) hide show
  1. tokencap-0.1.0/.claude/settings.local.json +39 -0
  2. tokencap-0.1.0/.github/workflows/ci.yml +49 -0
  3. tokencap-0.1.0/.github/workflows/publish.yml +34 -0
  4. tokencap-0.1.0/.github/workflows/version-check.yml +34 -0
  5. tokencap-0.1.0/.gitignore +10 -0
  6. tokencap-0.1.0/ARCHITECTURE.md +1762 -0
  7. tokencap-0.1.0/CHANGELOG.md +20 -0
  8. tokencap-0.1.0/CLAUDE.md +293 -0
  9. tokencap-0.1.0/CONTRIBUTING.md +129 -0
  10. tokencap-0.1.0/DECISIONS.md +881 -0
  11. tokencap-0.1.0/LICENSE +201 -0
  12. tokencap-0.1.0/Makefile +27 -0
  13. tokencap-0.1.0/PKG-INFO +798 -0
  14. tokencap-0.1.0/README.md +746 -0
  15. tokencap-0.1.0/RELEASING.md +16 -0
  16. tokencap-0.1.0/docker/docker-compose.redis.yml +6 -0
  17. tokencap-0.1.0/pyproject.toml +84 -0
  18. tokencap-0.1.0/scripts/smoke_test.py +2047 -0
  19. tokencap-0.1.0/tests/__init__.py +0 -0
  20. tokencap-0.1.0/tests/conftest.py +202 -0
  21. tokencap-0.1.0/tests/integration/__init__.py +0 -0
  22. tokencap-0.1.0/tests/integration/test_anthropic.py +171 -0
  23. tokencap-0.1.0/tests/integration/test_drop_in.py +440 -0
  24. tokencap-0.1.0/tests/integration/test_openai.py +144 -0
  25. tokencap-0.1.0/tests/integration/test_patch.py +339 -0
  26. tokencap-0.1.0/tests/live/__init__.py +0 -0
  27. tokencap-0.1.0/tests/live/test_anthropic_live.py +66 -0
  28. tokencap-0.1.0/tests/live/test_openai_live.py +65 -0
  29. tokencap-0.1.0/tests/live/test_patch_live.py +151 -0
  30. tokencap-0.1.0/tests/live/test_redis_live.py +98 -0
  31. tokencap-0.1.0/tests/unit/__init__.py +0 -0
  32. tokencap-0.1.0/tests/unit/test_backends.py +584 -0
  33. tokencap-0.1.0/tests/unit/test_guard.py +225 -0
  34. tokencap-0.1.0/tests/unit/test_interceptor.py +669 -0
  35. tokencap-0.1.0/tests/unit/test_patch.py +174 -0
  36. tokencap-0.1.0/tests/unit/test_policy.py +106 -0
  37. tokencap-0.1.0/tests/unit/test_providers.py +128 -0
  38. tokencap-0.1.0/tests/unit/test_status.py +188 -0
  39. tokencap-0.1.0/tests/unit/test_telemetry.py +86 -0
  40. tokencap-0.1.0/tokencap/__init__.py +348 -0
  41. tokencap-0.1.0/tokencap/backends/__init__.py +0 -0
  42. tokencap-0.1.0/tokencap/backends/protocol.py +69 -0
  43. tokencap-0.1.0/tokencap/backends/redis.py +223 -0
  44. tokencap-0.1.0/tokencap/backends/sqlite.py +231 -0
  45. tokencap-0.1.0/tokencap/core/__init__.py +0 -0
  46. tokencap-0.1.0/tokencap/core/enums.py +35 -0
  47. tokencap-0.1.0/tokencap/core/exceptions.py +38 -0
  48. tokencap-0.1.0/tokencap/core/guard.py +164 -0
  49. tokencap-0.1.0/tokencap/core/policy.py +79 -0
  50. tokencap-0.1.0/tokencap/core/types.py +56 -0
  51. tokencap-0.1.0/tokencap/interceptor/__init__.py +0 -0
  52. tokencap-0.1.0/tokencap/interceptor/anthropic.py +129 -0
  53. tokencap-0.1.0/tokencap/interceptor/base.py +346 -0
  54. tokencap-0.1.0/tokencap/interceptor/openai.py +157 -0
  55. tokencap-0.1.0/tokencap/providers/__init__.py +0 -0
  56. tokencap-0.1.0/tokencap/providers/anthropic.py +51 -0
  57. tokencap-0.1.0/tokencap/providers/openai.py +64 -0
  58. tokencap-0.1.0/tokencap/providers/protocol.py +39 -0
  59. tokencap-0.1.0/tokencap/py.typed +0 -0
  60. tokencap-0.1.0/tokencap/status/__init__.py +0 -0
  61. tokencap-0.1.0/tokencap/status/api.py +83 -0
  62. tokencap-0.1.0/tokencap/telemetry/__init__.py +0 -0
  63. tokencap-0.1.0/tokencap/telemetry/otel.py +102 -0
@@ -0,0 +1,39 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(git checkout:*)",
5
+ "Bash(pip install:*)",
6
+ "Bash(make lint:*)",
7
+ "Bash(make test:*)",
8
+ "Bash(python3 -m pytest tests/unit/test_backends.py::TestConcurrentWrites -v --count=5)",
9
+ "Bash(python3 -m pytest tests/unit/test_backends.py::TestConcurrentWrites -v)",
10
+ "Bash(git add:*)",
11
+ "Bash(git commit:*)",
12
+ "Bash(git rm:*)",
13
+ "Bash(git push:*)",
14
+ "Bash(gh pr:*)",
15
+ "Bash(git revert:*)",
16
+ "Bash(git fetch:*)",
17
+ "Bash(git merge:*)",
18
+ "Bash(ruff check:*)",
19
+ "Bash(python3:*)",
20
+ "Bash(gh run:*)",
21
+ "Bash(make test-live:*)",
22
+ "Bash(mypy --strict tokencap --show-error-codes)",
23
+ "Bash(make redis-up:*)",
24
+ "Bash(make redis-down:*)",
25
+ "Bash(find tokencap:*)",
26
+ "Bash(sort -k2)",
27
+ "Bash(git:*)",
28
+ "Bash(python -m mypy --strict tokencap/backends/redis.py tokencap/telemetry/otel.py)",
29
+ "Bash(source ~/.zshrc)",
30
+ "Bash(python scripts/smoke_test.py)",
31
+ "Bash(grep -c '\"\"hi\"\"' scripts/smoke_test.py)",
32
+ "Bash(supported\" because pytest-asyncio was not in dev dependencies. Add:*)",
33
+ "Bash(to track:*)",
34
+ "Bash(giving you:*)",
35
+ "Bash(pipeline run is spending.\":*)",
36
+ "Bash(twine check:*)"
37
+ ]
38
+ }
39
+ }
@@ -0,0 +1,49 @@
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
+ services:
13
+ redis:
14
+ image: redis:7-alpine
15
+ ports:
16
+ - 6379:6379
17
+ options: >-
18
+ --health-cmd "redis-cli ping"
19
+ --health-interval 5s
20
+ --health-timeout 3s
21
+ --health-retries 5
22
+ steps:
23
+ - uses: actions/checkout@v4
24
+ - uses: actions/setup-python@v5
25
+ with:
26
+ python-version: |
27
+ 3.9
28
+ 3.10
29
+ 3.11
30
+ 3.12
31
+ 3.13
32
+ - name: Lint
33
+ run: |
34
+ pip install -e ".[dev]"
35
+ make lint
36
+ - name: Test all Python versions
37
+ run: |
38
+ for py in 3.9 3.10 3.11 3.12 3.13; do
39
+ echo "::group::Python $py"
40
+ "python$py" -m pip install -e ".[dev]"
41
+ make test PYTHON="python$py"
42
+ echo "::endgroup::"
43
+ done
44
+ - name: Live tests (mock providers, real Redis)
45
+ run: |
46
+ pip install redis
47
+ make test-live
48
+ env:
49
+ REDIS_URL: redis://localhost:6379
@@ -0,0 +1,34 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ permissions:
8
+ id-token: write
9
+ contents: read
10
+
11
+ jobs:
12
+ publish:
13
+ runs-on: ubuntu-latest
14
+ environment:
15
+ name: pypi
16
+ url: https://pypi.org/project/tokencap/
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+
20
+ - uses: actions/setup-python@v5
21
+ with:
22
+ python-version: "3.11"
23
+
24
+ - name: Install build tools
25
+ run: pip install build twine
26
+
27
+ - name: Build package
28
+ run: python -m build
29
+
30
+ - name: Check package
31
+ run: twine check dist/*
32
+
33
+ - name: Publish to PyPI
34
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,34 @@
1
+ name: Version Check
2
+
3
+ on:
4
+ pull_request:
5
+ branches: [main]
6
+
7
+ jobs:
8
+ check-version:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ with:
13
+ fetch-depth: 0
14
+
15
+ - name: Check version bump for release PRs
16
+ run: |
17
+ PR_VERSION=$(grep '^version' pyproject.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
18
+ git fetch origin main
19
+ MAIN_VERSION=$(git show origin/main:pyproject.toml | grep '^version' | head -1 | sed 's/.*"\(.*\)".*/\1/')
20
+
21
+ echo "PR version: $PR_VERSION"
22
+ echo "Main version: $MAIN_VERSION"
23
+
24
+ PR_TITLE="${{ github.event.pull_request.title }}"
25
+ PR_TITLE_LOWER=$(echo "$PR_TITLE" | tr '[:upper:]' '[:lower:]')
26
+
27
+ if [ "$PR_VERSION" = "$MAIN_VERSION" ]; then
28
+ if echo "$PR_TITLE_LOWER" | grep -qE 'release|publish'; then
29
+ echo "::error::Version $PR_VERSION is the same as main. Bump the version in pyproject.toml before publishing."
30
+ exit 1
31
+ fi
32
+ fi
33
+
34
+ echo "Version check passed."
@@ -0,0 +1,10 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.egg-info/
4
+ dist/
5
+ build/
6
+ .pytest_cache/
7
+ .mypy_cache/
8
+ .ruff_cache/
9
+ *.db
10
+ .idea/