lingua-proxy 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 (48) hide show
  1. lingua_proxy-0.1.0/.github/ISSUE_TEMPLATE/bug_report.yml +50 -0
  2. lingua_proxy-0.1.0/.github/ISSUE_TEMPLATE/config.yml +5 -0
  3. lingua_proxy-0.1.0/.github/ISSUE_TEMPLATE/feature_request.yml +26 -0
  4. lingua_proxy-0.1.0/.github/ISSUE_TEMPLATE/other.md +12 -0
  5. lingua_proxy-0.1.0/.github/workflows/ci.yml +57 -0
  6. lingua_proxy-0.1.0/.github/workflows/release.yml +72 -0
  7. lingua_proxy-0.1.0/.gitignore +17 -0
  8. lingua_proxy-0.1.0/CHANGELOG.md +43 -0
  9. lingua_proxy-0.1.0/CODE_OF_CONDUCT.md +116 -0
  10. lingua_proxy-0.1.0/CONTRIBUTING.md +86 -0
  11. lingua_proxy-0.1.0/LICENSE +21 -0
  12. lingua_proxy-0.1.0/PKG-INFO +260 -0
  13. lingua_proxy-0.1.0/README.md +227 -0
  14. lingua_proxy-0.1.0/SECURITY.md +33 -0
  15. lingua_proxy-0.1.0/lingua_proxy/__init__.py +5 -0
  16. lingua_proxy-0.1.0/lingua_proxy/bench.py +185 -0
  17. lingua_proxy-0.1.0/lingua_proxy/bench_corpus.jsonl +21 -0
  18. lingua_proxy-0.1.0/lingua_proxy/bench_runner.py +109 -0
  19. lingua_proxy-0.1.0/lingua_proxy/cli.py +301 -0
  20. lingua_proxy-0.1.0/lingua_proxy/codecs.py +298 -0
  21. lingua_proxy-0.1.0/lingua_proxy/config.py +181 -0
  22. lingua_proxy-0.1.0/lingua_proxy/cost_log.py +323 -0
  23. lingua_proxy-0.1.0/lingua_proxy/detector.py +165 -0
  24. lingua_proxy-0.1.0/lingua_proxy/doctor.py +173 -0
  25. lingua_proxy-0.1.0/lingua_proxy/memo.py +223 -0
  26. lingua_proxy-0.1.0/lingua_proxy/pipeline.py +265 -0
  27. lingua_proxy-0.1.0/lingua_proxy/proxy.py +469 -0
  28. lingua_proxy-0.1.0/lingua_proxy/segments.py +203 -0
  29. lingua_proxy-0.1.0/lingua_proxy/streaming.py +354 -0
  30. lingua_proxy-0.1.0/lingua_proxy/translator.py +242 -0
  31. lingua_proxy-0.1.0/lingua_proxy/wrap.py +196 -0
  32. lingua_proxy-0.1.0/pyproject.toml +71 -0
  33. lingua_proxy-0.1.0/tests/conftest.py +184 -0
  34. lingua_proxy-0.1.0/tests/fixtures/bench_recorded.json +184 -0
  35. lingua_proxy-0.1.0/tests/test_bench.py +175 -0
  36. lingua_proxy-0.1.0/tests/test_cli.py +302 -0
  37. lingua_proxy-0.1.0/tests/test_codecs.py +351 -0
  38. lingua_proxy-0.1.0/tests/test_config.py +173 -0
  39. lingua_proxy-0.1.0/tests/test_cost_log.py +298 -0
  40. lingua_proxy-0.1.0/tests/test_detector.py +107 -0
  41. lingua_proxy-0.1.0/tests/test_harness.py +126 -0
  42. lingua_proxy-0.1.0/tests/test_memo.py +163 -0
  43. lingua_proxy-0.1.0/tests/test_pipeline.py +525 -0
  44. lingua_proxy-0.1.0/tests/test_proxy_passthrough.py +243 -0
  45. lingua_proxy-0.1.0/tests/test_segments.py +195 -0
  46. lingua_proxy-0.1.0/tests/test_streaming.py +228 -0
  47. lingua_proxy-0.1.0/tests/test_streaming_e2e.py +342 -0
  48. lingua_proxy-0.1.0/tests/test_translator.py +233 -0
@@ -0,0 +1,50 @@
1
+ name: Bug report
2
+ description: Something behaves differently than documented
3
+ labels: ["bug"]
4
+ body:
5
+ - type: markdown
6
+ attributes:
7
+ value: |
8
+ Please do not paste prompt content you would not publish. In particular,
9
+ never attach `~/.lingua-proxy/memo.jsonl` — it contains your prompts in
10
+ plaintext.
11
+
12
+ - type: textarea
13
+ id: what-happened
14
+ attributes:
15
+ label: What happened
16
+ description: What did you expect, and what happened instead?
17
+ validations:
18
+ required: true
19
+
20
+ - type: textarea
21
+ id: reproduce
22
+ attributes:
23
+ label: How to reproduce
24
+ placeholder: |
25
+ 1. Start the proxy with ...
26
+ 2. Send ...
27
+ 3. Observe ...
28
+ validations:
29
+ required: true
30
+
31
+ - type: textarea
32
+ id: doctor
33
+ attributes:
34
+ label: Output of `lingua-proxy doctor`
35
+ description: This redacts credentials automatically.
36
+ render: text
37
+ validations:
38
+ required: true
39
+
40
+ - type: input
41
+ id: language
42
+ attributes:
43
+ label: Input language
44
+ placeholder: Korean, Japanese, Arabic, ...
45
+
46
+ - type: input
47
+ id: model
48
+ attributes:
49
+ label: Model
50
+ placeholder: claude-sonnet-4-6
@@ -0,0 +1,5 @@
1
+ blank_issues_enabled: true
2
+ contact_links:
3
+ - name: Security vulnerability
4
+ url: https://github.com/hanyoungYoo/lingua-proxy/security/advisories/new
5
+ about: Please report security issues privately, not as a public issue.
@@ -0,0 +1,26 @@
1
+ name: Feature request
2
+ description: Suggest an improvement
3
+ labels: ["enhancement"]
4
+ body:
5
+ - type: textarea
6
+ id: problem
7
+ attributes:
8
+ label: What problem would this solve?
9
+ description: Please describe the situation rather than only the solution.
10
+ validations:
11
+ required: true
12
+
13
+ - type: textarea
14
+ id: proposal
15
+ attributes:
16
+ label: What would you like it to do?
17
+ validations:
18
+ required: true
19
+
20
+ - type: textarea
21
+ id: cost
22
+ attributes:
23
+ label: Does this affect the cost tradeoff?
24
+ description: >
25
+ This project exists to reduce token spend. If your idea changes what a
26
+ request costs, please say how.
@@ -0,0 +1,12 @@
1
+ ---
2
+ name: Question or other
3
+ about: Anything that is not a bug report or a feature request
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+ ---
8
+
9
+ <!--
10
+ Please do not paste prompt content you would not publish, and never attach
11
+ ~/.lingua-proxy/memo.jsonl — it contains your prompts in plaintext.
12
+ -->
@@ -0,0 +1,57 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ workflow_dispatch:
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ test:
14
+ runs-on: ${{ matrix.os }}
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ os: [ubuntu-latest, macos-latest]
19
+ python-version: ["3.12", "3.13"]
20
+
21
+ steps:
22
+ - uses: actions/checkout@v4
23
+
24
+ - name: Install uv
25
+ uses: astral-sh/setup-uv@v5
26
+ with:
27
+ enable-cache: true
28
+
29
+ - name: Set up Python ${{ matrix.python-version }}
30
+ run: uv python install ${{ matrix.python-version }}
31
+
32
+ - name: Install
33
+ run: uv venv && uv pip install -e ".[dev]"
34
+
35
+ - name: Lint
36
+ run: |
37
+ uv run ruff check .
38
+ uv run ruff format --check .
39
+
40
+ - name: Test
41
+ # The suite is fully offline: upstreams are mocked and translation is
42
+ # stubbed, so CI never needs a credential.
43
+ run: uv run pytest -q
44
+
45
+ build:
46
+ runs-on: ubuntu-latest
47
+ steps:
48
+ - uses: actions/checkout@v4
49
+ - uses: astral-sh/setup-uv@v5
50
+ - name: Build distributions
51
+ run: uv build
52
+ - name: Check metadata
53
+ run: uvx twine check dist/*
54
+ - uses: actions/upload-artifact@v4
55
+ with:
56
+ name: dist
57
+ path: dist/
@@ -0,0 +1,72 @@
1
+ name: Release
2
+
3
+ # Publishes to PyPI when a version tag is pushed.
4
+ #
5
+ # Authentication uses PyPI Trusted Publishing (OpenID Connect): GitHub proves
6
+ # this workflow's identity directly to PyPI, so there is no API token to
7
+ # create, store, rotate, or leak. Configure it once at
8
+ # https://pypi.org/manage/account/publishing/
9
+ on:
10
+ push:
11
+ tags: ["v*"]
12
+ workflow_dispatch:
13
+
14
+ permissions:
15
+ contents: read
16
+
17
+ jobs:
18
+ # Never publish something that does not pass its own tests.
19
+ test:
20
+ runs-on: ubuntu-latest
21
+ strategy:
22
+ matrix:
23
+ python-version: ["3.12", "3.13"]
24
+ steps:
25
+ - uses: actions/checkout@v4
26
+ - uses: astral-sh/setup-uv@v5
27
+ with:
28
+ enable-cache: true
29
+ - run: uv python install ${{ matrix.python-version }}
30
+ - run: uv venv && uv pip install -e ".[dev]"
31
+ - run: uv run ruff check .
32
+ - run: uv run pytest -q
33
+
34
+ build:
35
+ needs: test
36
+ runs-on: ubuntu-latest
37
+ steps:
38
+ - uses: actions/checkout@v4
39
+ - uses: astral-sh/setup-uv@v5
40
+
41
+ - name: Verify the tag matches the packaged version
42
+ # A tag that disagrees with pyproject.toml would publish a release
43
+ # under the wrong number, which cannot be undone on PyPI.
44
+ if: startsWith(github.ref, 'refs/tags/v')
45
+ run: |
46
+ TAG="${GITHUB_REF_NAME#v}"
47
+ PKG=$(grep -m1 '^version' pyproject.toml | sed 's/.*"\(.*\)".*/\1/')
48
+ echo "tag=$TAG packaged=$PKG"
49
+ test "$TAG" = "$PKG" || { echo "::error::tag $TAG != version $PKG"; exit 1; }
50
+
51
+ - run: uv build
52
+ - run: uvx twine check dist/*
53
+
54
+ - uses: actions/upload-artifact@v4
55
+ with:
56
+ name: dist
57
+ path: dist/
58
+
59
+ publish:
60
+ needs: build
61
+ runs-on: ubuntu-latest
62
+ environment:
63
+ name: pypi
64
+ url: https://pypi.org/p/lingua-proxy
65
+ permissions:
66
+ id-token: write # required for Trusted Publishing
67
+ steps:
68
+ - uses: actions/download-artifact@v4
69
+ with:
70
+ name: dist
71
+ path: dist/
72
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,17 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ venv/
5
+ *.egg-info/
6
+ dist/
7
+ build/
8
+ .pytest_cache/
9
+ .ruff_cache/
10
+ .coverage
11
+ htmlcov/
12
+
13
+ # never commit local runtime state or private endpoints
14
+ .lingua-proxy/
15
+ *.local.toml
16
+ *.local.json
17
+ tests/fixtures/*.local.json
@@ -0,0 +1,43 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project uses
5
+ [semantic versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.0] - 2026-09-10
10
+
11
+ First release. Alpha: the interfaces may still change.
12
+
13
+ ### Added
14
+
15
+ - Translating reverse proxy for the Anthropic Messages API
16
+ (`POST /v1/messages`) and the OpenAI-compatible chat API
17
+ (`POST /v1/chat/completions`). Everything else passes through untouched.
18
+ - Offline language detection with `lingua`. English input is a pure passthrough
19
+ with no added latency and no extra tokens.
20
+ - Technical-content masking, so fenced code, inline code, URLs, file paths,
21
+ JSON blobs and markup tags survive translation byte for byte.
22
+ - Bidirectional translation memo, in memory and on disk, which keeps resent
23
+ conversation history byte-stable so the upstream prompt cache keeps hitting.
24
+ - Streaming support. Text blocks are buffered per block and translated; tool
25
+ calls and reasoning stream through untouched, with keep-alives while a
26
+ translation is in flight.
27
+ - `wrap` and `unwrap` commands that patch and transactionally restore client
28
+ settings, chaining onto whatever gateway the client already points at.
29
+ - `doctor`, `dashboard`, and `bench` commands. The benchmark reports savings in
30
+ dollars and is able to report that a workload does not pay off.
31
+ - `x-lingua-bypass` header to skip translation for a single request.
32
+
33
+ ### Known limitations
34
+
35
+ - Savings apply to input tokens. Output tokens cost more and are not reduced,
36
+ so end-to-end savings are lower than the input-token figure.
37
+ - Streaming buffers each text block, so non-English text does not appear word
38
+ by word.
39
+ - macOS and Linux only.
40
+ - DeepL and LibreTranslate adapters are interface-only.
41
+
42
+ [Unreleased]: https://github.com/hanyoungYoo/lingua-proxy/compare/v0.1.0...HEAD
43
+ [0.1.0]: https://github.com/hanyoungYoo/lingua-proxy/releases/tag/v0.1.0
@@ -0,0 +1,116 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+
56
+ ## Enforcement
57
+
58
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
59
+ reported to the community leaders responsible for enforcement at
60
+ yhanyoung0411@gmail.com. All complaints will be reviewed and investigated
61
+ promptly and fairly.
62
+
63
+ All community leaders are obligated to respect the privacy and security of the
64
+ reporter of any incident.
65
+
66
+ ## Enforcement Guidelines
67
+
68
+ Community leaders will follow these Community Impact Guidelines in determining
69
+ the consequences for any action they deem in violation of this Code of Conduct:
70
+
71
+ ### 1. Correction
72
+
73
+ **Community Impact**: Use of inappropriate language or other behavior deemed
74
+ unprofessional or unwelcome in the community.
75
+
76
+ **Consequence**: A private, written warning from community leaders, providing
77
+ clarity around the nature of the violation and an explanation of why the
78
+ behavior was inappropriate. A public apology may be requested.
79
+
80
+ ### 2. Warning
81
+
82
+ **Community Impact**: A violation through a single incident or series of
83
+ actions.
84
+
85
+ **Consequence**: A warning with consequences for continued behavior. No
86
+ interaction with the people involved, including unsolicited interaction with
87
+ those enforcing the Code of Conduct, for a specified period of time.
88
+
89
+ ### 3. Temporary Ban
90
+
91
+ **Community Impact**: A serious violation of community standards, including
92
+ sustained inappropriate behavior.
93
+
94
+ **Consequence**: A temporary ban from any sort of interaction or public
95
+ communication with the community for a specified period of time.
96
+
97
+ ### 4. Permanent Ban
98
+
99
+ **Community Impact**: Demonstrating a pattern of violation of community
100
+ standards, including sustained inappropriate behavior, harassment of an
101
+ individual, or aggression toward or disparagement of classes of individuals.
102
+
103
+ **Consequence**: A permanent ban from any sort of public interaction within the
104
+ community.
105
+
106
+ ## Attribution
107
+
108
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
109
+ version 2.1, available at
110
+ https://www.contributor-covenant.org/version/2/1/code_of_conduct.html.
111
+
112
+ Community Impact Guidelines were inspired by
113
+ [Mozilla's code of conduct enforcement ladder][mozilla].
114
+
115
+ [homepage]: https://www.contributor-covenant.org
116
+ [mozilla]: https://github.com/mozilla/diversity
@@ -0,0 +1,86 @@
1
+ # Contributing
2
+
3
+ Thanks for considering a contribution.
4
+
5
+ ## Getting set up
6
+
7
+ Requires Python 3.12 or newer, and [uv](https://github.com/astral-sh/uv).
8
+
9
+ ```bash
10
+ uv venv && uv pip install -e ".[dev]"
11
+ ```
12
+
13
+ ```bash
14
+ uv run pytest
15
+ ```
16
+
17
+ ```bash
18
+ uv run ruff check . && uv run ruff format --check .
19
+ ```
20
+
21
+ The whole suite runs offline in a few seconds. No test may reach the network:
22
+ upstreams are mocked with `RecordingTransport` in `tests/conftest.py`, and
23
+ translation is stubbed by `FakeTranslator` so results stay deterministic.
24
+
25
+ ## How this project is built
26
+
27
+ Tests come first. Every module here was written by adding a failing test that
28
+ describes the behaviour, then the smallest implementation that satisfies it.
29
+ Please keep that shape — a pull request that changes behaviour should change or
30
+ add a test that would fail without it.
31
+
32
+ Three rules carry most of the design:
33
+
34
+ 1. **Fail open.** Any uncertainty — a translator error, a damaged placeholder,
35
+ an ambiguous language — must result in the user's original text being
36
+ forwarded untranslated. A missed saving is a rounding error. A corrupted
37
+ prompt is not.
38
+ 2. **Byte stability.** Text already translated in an earlier turn is reproduced
39
+ from the memo, never re-translated. Agentic clients resend the whole history
40
+ each turn, so anything else breaks the upstream prompt cache and costs more
41
+ than it saves.
42
+ 3. **No private endpoints.** The only hard-coded URLs are the public vendor
43
+ APIs. Everything else is resolved at runtime. `test_no_private_endpoints_committed_in_repo`
44
+ fails the build if a private host is committed.
45
+
46
+ ## Measuring cost claims
47
+
48
+ This project exists to make a claim about money, so please do not change the
49
+ documented savings figures by hand. Re-run the benchmark against a real upstream
50
+ and update the recorded fixture:
51
+
52
+ ```bash
53
+ LINGUA_BENCH_BASE_URL=https://your-upstream.example lingua-proxy bench
54
+ ```
55
+
56
+ A test asserts the README quotes the same number as
57
+ `tests/fixtures/bench_recorded.json`, so the two cannot drift apart. Note that
58
+ the benchmark spends real money and refuses to guess an endpoint for you.
59
+
60
+ ## Releasing
61
+
62
+ Releases are published to PyPI by CI, never from a laptop. The workflow uses
63
+ PyPI Trusted Publishing, so there is no API token to store or rotate.
64
+
65
+ 1. Update the version in `pyproject.toml` and add a section to `CHANGELOG.md`.
66
+ 2. Commit, then tag and push:
67
+
68
+ ```bash
69
+ git tag v0.1.0 && git push origin v0.1.0
70
+ ```
71
+
72
+ The release workflow runs the tests, refuses to continue if the tag disagrees
73
+ with the packaged version, builds, and publishes. A version number on PyPI can
74
+ never be reused, which is why the check exists.
75
+
76
+ ## Reporting bugs
77
+
78
+ Please include the output of `lingua-proxy doctor`, which redacts credentials.
79
+ Never paste a prompt containing anything you would not publish — and note that
80
+ `~/.lingua-proxy/memo.jsonl` contains your prompts in plaintext, so do not
81
+ attach it.
82
+
83
+ ## Areas that need work
84
+
85
+ See the roadmap in the README. The largest open item is sentence-boundary
86
+ streaming translation, which would remove the per-block buffering caveat.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Hanyoung Yoo
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.