tokenome 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 (58) hide show
  1. tokenome-0.1.0/.github/ISSUE_TEMPLATE/analysis.yml +46 -0
  2. tokenome-0.1.0/.github/ISSUE_TEMPLATE/bug.yml +65 -0
  3. tokenome-0.1.0/.github/ISSUE_TEMPLATE/config.yml +1 -0
  4. tokenome-0.1.0/.github/ISSUE_TEMPLATE/feature.yml +55 -0
  5. tokenome-0.1.0/.github/pull_request_template.md +32 -0
  6. tokenome-0.1.0/.github/workflows/ci.yml +57 -0
  7. tokenome-0.1.0/.github/workflows/pr-ci-summary-comment.yml +36 -0
  8. tokenome-0.1.0/.github/workflows/publish.yml +81 -0
  9. tokenome-0.1.0/.github/workflows/quality.yml +63 -0
  10. tokenome-0.1.0/.github/workflows/security-supply-chain.yml +24 -0
  11. tokenome-0.1.0/.gitignore +6 -0
  12. tokenome-0.1.0/.pre-commit-config.yaml +39 -0
  13. tokenome-0.1.0/LICENSE +21 -0
  14. tokenome-0.1.0/PKG-INFO +602 -0
  15. tokenome-0.1.0/README.md +560 -0
  16. tokenome-0.1.0/changelog/20260502.md +7 -0
  17. tokenome-0.1.0/changelog/20260518.md +42 -0
  18. tokenome-0.1.0/docs/CODE_OF_CONDUCT.md +22 -0
  19. tokenome-0.1.0/docs/CONTRIBUTING.md +100 -0
  20. tokenome-0.1.0/docs/INSTALLATION.md +190 -0
  21. tokenome-0.1.0/docs/SECURITY.md +27 -0
  22. tokenome-0.1.0/docs/plans/2025-06-21-openai-api-coverage-expansion.md +690 -0
  23. tokenome-0.1.0/pyproject.toml +79 -0
  24. tokenome-0.1.0/scripts/pr_ci_summary_comment.py +467 -0
  25. tokenome-0.1.0/scripts/smoke_install.sh +43 -0
  26. tokenome-0.1.0/scripts/test_flush_mechanism.py +387 -0
  27. tokenome-0.1.0/src/tokenome/__init__.py +17 -0
  28. tokenome-0.1.0/src/tokenome/client.py +350 -0
  29. tokenome-0.1.0/src/tokenome/config.py +37 -0
  30. tokenome-0.1.0/src/tokenome/context.py +87 -0
  31. tokenome-0.1.0/src/tokenome/delivery/__init__.py +7 -0
  32. tokenome-0.1.0/src/tokenome/delivery/result.py +55 -0
  33. tokenome-0.1.0/src/tokenome/delivery/sender.py +163 -0
  34. tokenome-0.1.0/src/tokenome/delivery/worker.py +296 -0
  35. tokenome-0.1.0/src/tokenome/errors.py +14 -0
  36. tokenome-0.1.0/src/tokenome/limits.py +5 -0
  37. tokenome-0.1.0/src/tokenome/models.py +69 -0
  38. tokenome-0.1.0/src/tokenome/providers/__init__.py +6 -0
  39. tokenome-0.1.0/src/tokenome/providers/anthropic.py +100 -0
  40. tokenome-0.1.0/src/tokenome/providers/openai/__init__.py +919 -0
  41. tokenome-0.1.0/src/tokenome/serialization.py +68 -0
  42. tokenome-0.1.0/src/tokenome/spool/__init__.py +7 -0
  43. tokenome-0.1.0/src/tokenome/spool/memory.py +148 -0
  44. tokenome-0.1.0/src/tokenome/spool/protocol.py +48 -0
  45. tokenome-0.1.0/src/tokenome/spool/sqlite.py +351 -0
  46. tokenome-0.1.0/src/tokenome/wrapper.py +17 -0
  47. tokenome-0.1.0/tests/conftest.py +5 -0
  48. tokenome-0.1.0/tests/delivery/test_worker.py +538 -0
  49. tokenome-0.1.0/tests/test_context.py +22 -0
  50. tokenome-0.1.0/tests/test_event_shape.py +47 -0
  51. tokenome-0.1.0/tests/test_init_from_env.py +18 -0
  52. tokenome-0.1.0/tests/test_instrumentation_anthropic.py +52 -0
  53. tokenome-0.1.0/tests/test_instrumentation_openai.py +905 -0
  54. tokenome-0.1.0/tests/test_metadata_config.py +9 -0
  55. tokenome-0.1.0/tests/test_public_imports.py +11 -0
  56. tokenome-0.1.0/tests/test_standalone_bootstrap.py +14 -0
  57. tokenome-0.1.0/tests/test_transport.py +72 -0
  58. tokenome-0.1.0/uv.lock +1337 -0
@@ -0,0 +1,46 @@
1
+ name: Investigation / analysis task
2
+ description: Analyze SDK behavior/design before coding.
3
+ title: "[analysis][sdk]: "
4
+ labels: [analysis, needs-triage]
5
+ body:
6
+ - type: textarea
7
+ id: question
8
+ attributes:
9
+ label: Question to answer
10
+ placeholder: "What is unknown?"
11
+ validations:
12
+ required: true
13
+ - type: textarea
14
+ id: context
15
+ attributes:
16
+ label: Context
17
+ placeholder: "provider/framework versions, sample payloads, prior attempts"
18
+ validations:
19
+ required: true
20
+ - type: textarea
21
+ id: constraints
22
+ attributes:
23
+ label: Constraints
24
+ placeholder: "backward compatibility, fail-open, metadata-only"
25
+ - type: textarea
26
+ id: analysis_plan
27
+ attributes:
28
+ label: Analysis plan (discussion first)
29
+ placeholder: |
30
+ - inspect code path
31
+ - run focused tests
32
+ - compare options
33
+ validations:
34
+ required: true
35
+ - type: textarea
36
+ id: decision
37
+ attributes:
38
+ label: Decision log
39
+ description: Fill after discussion. Chosen approach + trade-offs.
40
+ - type: textarea
41
+ id: execution
42
+ attributes:
43
+ label: Execution plan
44
+ placeholder: |
45
+ - [ ] implementation step
46
+ - [ ] tests/docs updates
@@ -0,0 +1,65 @@
1
+ name: Bug report
2
+ description: Report broken SDK behavior (instrumentation, transport, context, payload).
3
+ title: "[bug][sdk]: "
4
+ labels: [bug, needs-triage]
5
+ body:
6
+ - type: checkboxes
7
+ id: checks
8
+ attributes:
9
+ label: Pre-flight
10
+ options:
11
+ - label: I searched existing issues.
12
+ required: true
13
+ - label: I tested on latest SDK version or Development branch.
14
+ required: true
15
+ - type: input
16
+ id: version
17
+ attributes:
18
+ label: SDK version
19
+ placeholder: "0.1.x / commit sha"
20
+ validations:
21
+ required: true
22
+ - type: textarea
23
+ id: problem
24
+ attributes:
25
+ label: Problem statement
26
+ placeholder: "instrument_openai does X instead of Y"
27
+ validations:
28
+ required: true
29
+ - type: textarea
30
+ id: repro
31
+ attributes:
32
+ label: Minimal reproduction
33
+ placeholder: |
34
+ ```python
35
+ # minimal script
36
+ ```
37
+ validations:
38
+ required: true
39
+ - type: textarea
40
+ id: expected
41
+ attributes:
42
+ label: Expected vs actual
43
+ placeholder: "Expected: ...\nActual: ..."
44
+ validations:
45
+ required: true
46
+ - type: textarea
47
+ id: analysis
48
+ attributes:
49
+ label: Analysis notes (we discuss here)
50
+ placeholder: "likely module/function and why"
51
+ - type: textarea
52
+ id: resolution
53
+ attributes:
54
+ label: Resolution plan (to be filled before coding)
55
+ placeholder: |
56
+ - patch area
57
+ - tests to add
58
+ - backward-compat check
59
+ - type: checkboxes
60
+ id: privacy
61
+ attributes:
62
+ label: Data safety
63
+ options:
64
+ - label: No prompt/completion text is required to reproduce.
65
+ required: false
@@ -0,0 +1 @@
1
+ blank_issues_enabled: false
@@ -0,0 +1,55 @@
1
+ name: Feature request
2
+ description: Request SDK capability (new provider metadata, instrumentation, API ergonomics).
3
+ title: "[feature][sdk]: "
4
+ labels: [enhancement, needs-triage]
5
+ body:
6
+ - type: textarea
7
+ id: outcome
8
+ attributes:
9
+ label: Desired outcome
10
+ placeholder: "What devs should be able to do after this feature"
11
+ validations:
12
+ required: true
13
+ - type: textarea
14
+ id: integration
15
+ attributes:
16
+ label: Integration context
17
+ placeholder: "framework/provider/runtime context"
18
+ validations:
19
+ required: true
20
+ - type: textarea
21
+ id: api
22
+ attributes:
23
+ label: Proposed API/usage shape
24
+ placeholder: |
25
+ ```python
26
+ # desired usage
27
+ ```
28
+ validations:
29
+ required: true
30
+ - type: textarea
31
+ id: compatibility
32
+ attributes:
33
+ label: Backward compatibility expectations
34
+ placeholder: "what must remain stable"
35
+ - type: textarea
36
+ id: acceptance
37
+ attributes:
38
+ label: Acceptance criteria
39
+ placeholder: |
40
+ - [ ] criterion 1
41
+ - [ ] criterion 2
42
+ validations:
43
+ required: true
44
+ - type: textarea
45
+ id: analysis
46
+ attributes:
47
+ label: Analysis notes (we discuss here)
48
+ placeholder: "trade-offs, data safety, fail-open impact"
49
+ - type: textarea
50
+ id: resolution
51
+ attributes:
52
+ label: Resolution plan (to be filled before coding)
53
+ placeholder: |
54
+ - instrumentation/transport changes
55
+ - tests + docs
@@ -0,0 +1,32 @@
1
+ ## Summary
2
+ - what changed
3
+ - why now
4
+
5
+ ## Linked issue
6
+ Closes #<issue-id>
7
+
8
+ ## Problem analysis (before code)
9
+ - integration gap
10
+ - SDK API constraints
11
+ - backward-compatibility notes
12
+
13
+ ## Changes
14
+ - [ ] event schema/payload updates
15
+ - [ ] instrumentation updates (openai/anthropic/framework)
16
+ - [ ] transport/retry behavior reviewed
17
+ - [ ] tests added/updated
18
+ - [ ] docs/examples updated
19
+
20
+ ## Validation
21
+ - [ ] `uv run ruff format --check src tests`
22
+ - [ ] `uv run ruff check src tests`
23
+ - [ ] `PYTHONPATH=src uv run pytest -q`
24
+
25
+ ## Compatibility & safety
26
+ - [ ] fail-open behavior preserved
27
+ - [ ] no prompt/response leakage by default
28
+ - [ ] no breaking API change without migration note
29
+
30
+ ## Notes for reviewer
31
+ - focus areas
32
+ - known follow-ups
@@ -0,0 +1,57 @@
1
+ name: ci
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches: [Development, Production]
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ concurrency:
12
+ group: ci-${{ github.workflow }}-${{ github.ref }}
13
+ cancel-in-progress: true
14
+
15
+ jobs:
16
+ smoke-install:
17
+ runs-on: ubuntu-latest
18
+ steps:
19
+ - uses: actions/checkout@v5
20
+ - uses: astral-sh/setup-uv@v7
21
+ with:
22
+ python-version: "3.12"
23
+ - name: Clean install smoke checks
24
+ run: ./scripts/smoke_install.sh
25
+
26
+ test:
27
+ needs: smoke-install
28
+ runs-on: ubuntu-latest
29
+ strategy:
30
+ matrix:
31
+ python-version: ["3.11", "3.12", "3.13"]
32
+ steps:
33
+ - uses: actions/checkout@v5
34
+ with:
35
+ fetch-depth: 0
36
+ - uses: astral-sh/setup-uv@v7
37
+ with:
38
+ python-version: ${{ matrix.python-version }}
39
+ - run: uv sync --extra dev
40
+ - name: Wrapper + bootstrap ownership tests
41
+ run: >-
42
+ uv run pytest -q
43
+ tests/test_public_imports.py
44
+ tests/test_standalone_bootstrap.py
45
+ tests/test_init_from_env.py
46
+ tests/test_instrumentation_openai.py
47
+ tests/test_instrumentation_anthropic.py
48
+ tests/test_transport.py
49
+ - name: Full test suite
50
+ run: uv run pytest -q --json-report --json-report-file=pytest-report.json
51
+ - name: Upload pytest report
52
+ if: always()
53
+ uses: actions/upload-artifact@v4
54
+ with:
55
+ name: pytest-report-${{ matrix.python-version }}
56
+ path: pytest-report.json
57
+ retention-days: 7
@@ -0,0 +1,36 @@
1
+ name: pr-ci-summary-comment
2
+
3
+ on:
4
+ workflow_run:
5
+ workflows:
6
+ - ci
7
+ - quality
8
+ - security-supply-chain
9
+ types:
10
+ - completed
11
+
12
+ permissions:
13
+ actions: read
14
+ contents: read
15
+ pull-requests: write
16
+ issues: write
17
+
18
+ jobs:
19
+ pr-ci-summary-comment:
20
+ if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.pull_requests[0].number != null
21
+ runs-on: ubuntu-latest
22
+ steps:
23
+ - name: Checkout
24
+ uses: actions/checkout@v5
25
+
26
+ - name: Setup uv
27
+ uses: astral-sh/setup-uv@v7
28
+ with:
29
+ python-version: "3.12"
30
+
31
+ - name: Post replace-on-rerun PR CI summary comment
32
+ env:
33
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34
+ REQUIRED_WORKFLOW_FILES: ci.yml,quality.yml,security-supply-chain.yml
35
+ PR_CI_SUMMARY_MARKER: <!-- pr-ci-summary-comment:marker -->
36
+ run: uv run scripts/pr_ci_summary_comment.py
@@ -0,0 +1,81 @@
1
+ name: publish
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ permissions:
8
+ contents: read
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v5
15
+ - uses: astral-sh/setup-uv@v7
16
+ with:
17
+ python-version: "3.12"
18
+ - run: uv build
19
+ - name: Upload build artifacts
20
+ uses: actions/upload-artifact@v4
21
+ with:
22
+ name: dist
23
+ path: dist/
24
+ retention-days: 1
25
+
26
+ test:
27
+ needs: build
28
+ runs-on: ubuntu-latest
29
+ strategy:
30
+ matrix:
31
+ python-version: ["3.11", "3.12", "3.13"]
32
+ steps:
33
+ - uses: actions/checkout@v5
34
+ - uses: astral-sh/setup-uv@v7
35
+ with:
36
+ python-version: ${{ matrix.python-version }}
37
+ - run: uv sync --extra dev
38
+ - run: uv run ruff format --check src tests
39
+ - run: uv run ruff check src tests
40
+ - run: uv run isort --check-only src tests
41
+ - run: uv run mypy src tests
42
+ - run: uv run pytest -q
43
+
44
+ testpypi:
45
+ needs: test
46
+ runs-on: ubuntu-latest
47
+ environment:
48
+ name: testpypi
49
+ url: https://test.pypi.org/project/tokenome
50
+ permissions:
51
+ id-token: write
52
+ steps:
53
+ - name: Download build artifacts
54
+ uses: actions/download-artifact@v4
55
+ with:
56
+ name: dist
57
+ path: dist/
58
+ - name: Publish to TestPyPI
59
+ uses: pypa/gh-action-pypi-publish@release/v1
60
+ with:
61
+ repository-url: https://test.pypi.org/legacy/
62
+ skip-existing: true
63
+
64
+ pypi:
65
+ needs: testpypi
66
+ runs-on: ubuntu-latest
67
+ environment:
68
+ name: pypi
69
+ url: https://pypi.org/project/tokenome
70
+ permissions:
71
+ id-token: write
72
+ steps:
73
+ - name: Download build artifacts
74
+ uses: actions/download-artifact@v4
75
+ with:
76
+ name: dist
77
+ path: dist/
78
+ - name: Publish to PyPI
79
+ uses: pypa/gh-action-pypi-publish@release/v1
80
+ with:
81
+ skip-existing: true
@@ -0,0 +1,63 @@
1
+ name: quality
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - Development
8
+ - Production
9
+
10
+ permissions:
11
+ contents: read
12
+
13
+ jobs:
14
+ format:
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v5
18
+ - uses: astral-sh/setup-uv@v7
19
+ with:
20
+ python-version: "3.12"
21
+ - run: uv sync --extra dev
22
+ - run: uv run ruff format --check src tests
23
+
24
+ lint:
25
+ runs-on: ubuntu-latest
26
+ steps:
27
+ - uses: actions/checkout@v5
28
+ - uses: astral-sh/setup-uv@v7
29
+ with:
30
+ python-version: "3.12"
31
+ - run: uv sync --extra dev
32
+ - run: uv run ruff check src tests
33
+
34
+ import-sort:
35
+ runs-on: ubuntu-latest
36
+ steps:
37
+ - uses: actions/checkout@v5
38
+ - uses: astral-sh/setup-uv@v7
39
+ with:
40
+ python-version: "3.12"
41
+ - run: uv sync --extra dev
42
+ - run: uv run isort --check-only src tests
43
+
44
+ mypy:
45
+ runs-on: ubuntu-latest
46
+ steps:
47
+ - uses: actions/checkout@v5
48
+ - uses: astral-sh/setup-uv@v7
49
+ with:
50
+ python-version: "3.12"
51
+ - run: uv sync --extra dev
52
+ - run: uv run mypy src tests
53
+
54
+ check-added-large-files:
55
+ runs-on: ubuntu-latest
56
+ steps:
57
+ - uses: actions/checkout@v5
58
+ - uses: actions/setup-python@v5
59
+ with:
60
+ python-version: "3.12"
61
+ - uses: pre-commit/action@v3.0.1
62
+ with:
63
+ extra_args: check-added-large-files --all-files
@@ -0,0 +1,24 @@
1
+ name: security-supply-chain
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - Development
8
+ release:
9
+ types: [published]
10
+
11
+ permissions:
12
+ contents: read
13
+
14
+ jobs:
15
+ pip-audit:
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - uses: actions/checkout@v5
19
+ - uses: astral-sh/setup-uv@v7
20
+ with:
21
+ python-version: "3.12"
22
+ - run: uv sync --extra dev
23
+ - name: Run pip-audit
24
+ run: uv run pip-audit --desc --format=json
@@ -0,0 +1,6 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+
@@ -0,0 +1,39 @@
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v5.0.0
4
+ hooks:
5
+ - id: check-yaml
6
+ - id: end-of-file-fixer
7
+ - id: trailing-whitespace
8
+ - id: check-added-large-files
9
+
10
+ - repo: https://github.com/astral-sh/ruff-pre-commit
11
+ rev: v0.11.13
12
+ hooks:
13
+ - id: ruff-format
14
+ args: [--line-length=100]
15
+ - id: ruff
16
+ args: [--fix, --exit-non-zero-on-fix]
17
+
18
+ - repo: local
19
+ hooks:
20
+ - id: smoke-install
21
+ name: smoke install (wheel + imports)
22
+ entry: ./scripts/smoke_install.sh
23
+ language: system
24
+ pass_filenames: false
25
+ stages: [manual, pre-push]
26
+ - id: pytest-required-ownership
27
+ name: pytest (framework + standalone ownership)
28
+ entry: >-
29
+ bash -lc 'uv run pytest -q
30
+ tests/test_standalone_bootstrap.py
31
+ tests/test_init_from_env.py
32
+ tests/test_public_imports.py'
33
+ language: system
34
+ pass_filenames: false
35
+ - id: pytest
36
+ name: pytest (full suite)
37
+ entry: bash -lc 'uv run pytest -q'
38
+ language: system
39
+ pass_filenames: false
tokenome-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Khodex Rei
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.