pyursa 1.0.0rc5__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 (68) hide show
  1. pyursa-1.0.0rc5/.github/workflows/ci.yml +77 -0
  2. pyursa-1.0.0rc5/.github/workflows/release.yml +41 -0
  3. pyursa-1.0.0rc5/.gitignore +18 -0
  4. pyursa-1.0.0rc5/CHANGELOG.md +153 -0
  5. pyursa-1.0.0rc5/CONTRIBUTING.md +31 -0
  6. pyursa-1.0.0rc5/LICENSE +202 -0
  7. pyursa-1.0.0rc5/NOTICE +4 -0
  8. pyursa-1.0.0rc5/PKG-INFO +140 -0
  9. pyursa-1.0.0rc5/README.md +83 -0
  10. pyursa-1.0.0rc5/SECURITY.md +49 -0
  11. pyursa-1.0.0rc5/benchmarks/README.md +119 -0
  12. pyursa-1.0.0rc5/benchmarks/agent_bench.py +828 -0
  13. pyursa-1.0.0rc5/ci/constraints-min.txt +6 -0
  14. pyursa-1.0.0rc5/docs/agents.md +73 -0
  15. pyursa-1.0.0rc5/docs/api.md +509 -0
  16. pyursa-1.0.0rc5/docs/guide.md +112 -0
  17. pyursa-1.0.0rc5/docs/index.md +63 -0
  18. pyursa-1.0.0rc5/docs/llm.md +132 -0
  19. pyursa-1.0.0rc5/docs/providers.md +116 -0
  20. pyursa-1.0.0rc5/docs/security.md +49 -0
  21. pyursa-1.0.0rc5/docs/semantics.md +33 -0
  22. pyursa-1.0.0rc5/docs/stability.md +37 -0
  23. pyursa-1.0.0rc5/docs/types.md +75 -0
  24. pyursa-1.0.0rc5/examples/quickstart.py +44 -0
  25. pyursa-1.0.0rc5/mkdocs.yml +21 -0
  26. pyursa-1.0.0rc5/pyproject.toml +64 -0
  27. pyursa-1.0.0rc5/scripts/check_providers.py +169 -0
  28. pyursa-1.0.0rc5/scripts/e2e.py +625 -0
  29. pyursa-1.0.0rc5/scripts/gen_api_docs.py +196 -0
  30. pyursa-1.0.0rc5/src/pyursa/__init__.py +88 -0
  31. pyursa-1.0.0rc5/src/pyursa/backends/__init__.py +28 -0
  32. pyursa-1.0.0rc5/src/pyursa/backends/base.py +169 -0
  33. pyursa-1.0.0rc5/src/pyursa/backends/castrules.py +22 -0
  34. pyursa-1.0.0rc5/src/pyursa/backends/duckdb_backend.py +484 -0
  35. pyursa-1.0.0rc5/src/pyursa/backends/polars_backend.py +353 -0
  36. pyursa-1.0.0rc5/src/pyursa/errors.py +125 -0
  37. pyursa-1.0.0rc5/src/pyursa/expr.py +792 -0
  38. pyursa-1.0.0rc5/src/pyursa/frame.py +460 -0
  39. pyursa-1.0.0rc5/src/pyursa/mcp_server.py +219 -0
  40. pyursa-1.0.0rc5/src/pyursa/parse.py +207 -0
  41. pyursa-1.0.0rc5/src/pyursa/plan.py +615 -0
  42. pyursa-1.0.0rc5/src/pyursa/providers.py +882 -0
  43. pyursa-1.0.0rc5/src/pyursa/py.typed +0 -0
  44. pyursa-1.0.0rc5/src/pyursa/redact.py +54 -0
  45. pyursa-1.0.0rc5/src/pyursa/semantic.py +571 -0
  46. pyursa-1.0.0rc5/src/pyursa/summarize.py +211 -0
  47. pyursa-1.0.0rc5/src/pyursa/tools.py +414 -0
  48. pyursa-1.0.0rc5/src/pyursa/types.py +447 -0
  49. pyursa-1.0.0rc5/tests/__init__.py +0 -0
  50. pyursa-1.0.0rc5/tests/conftest.py +34 -0
  51. pyursa-1.0.0rc5/tests/test_agent_features.py +79 -0
  52. pyursa-1.0.0rc5/tests/test_bedrock_sigv4.py +148 -0
  53. pyursa-1.0.0rc5/tests/test_bench_harness.py +144 -0
  54. pyursa-1.0.0rc5/tests/test_check_providers.py +67 -0
  55. pyursa-1.0.0rc5/tests/test_conformance.py +143 -0
  56. pyursa-1.0.0rc5/tests/test_conformance_v2.py +337 -0
  57. pyursa-1.0.0rc5/tests/test_errors.py +84 -0
  58. pyursa-1.0.0rc5/tests/test_llm_v2.py +153 -0
  59. pyursa-1.0.0rc5/tests/test_parse.py +53 -0
  60. pyursa-1.0.0rc5/tests/test_provider_mechanics.py +174 -0
  61. pyursa-1.0.0rc5/tests/test_provider_registry.py +193 -0
  62. pyursa-1.0.0rc5/tests/test_providers.py +164 -0
  63. pyursa-1.0.0rc5/tests/test_providers_aws_claude.py +238 -0
  64. pyursa-1.0.0rc5/tests/test_rate_limits.py +71 -0
  65. pyursa-1.0.0rc5/tests/test_review_findings.py +371 -0
  66. pyursa-1.0.0rc5/tests/test_security.py +155 -0
  67. pyursa-1.0.0rc5/tests/test_semantic.py +216 -0
  68. pyursa-1.0.0rc5/tests/test_tools.py +168 -0
@@ -0,0 +1,77 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ concurrency:
12
+ group: ${{ github.workflow }}-${{ github.ref }}
13
+ cancel-in-progress: true
14
+
15
+ jobs:
16
+ lint:
17
+ runs-on: ubuntu-latest
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+ - uses: actions/setup-python@v5
21
+ with:
22
+ python-version: "3.13"
23
+ - run: pip install ruff -e ".[all]"
24
+ - run: ruff check src tests scripts benchmarks
25
+ - name: API reference is up to date
26
+ run: python scripts/gen_api_docs.py --check
27
+
28
+ test:
29
+ name: test (${{ matrix.os }}, py${{ matrix.python }})
30
+ runs-on: ${{ matrix.os }}
31
+ strategy:
32
+ fail-fast: false
33
+ matrix:
34
+ os: [ubuntu-latest, macos-latest, windows-latest]
35
+ python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
36
+ steps:
37
+ - uses: actions/checkout@v4
38
+ - uses: actions/setup-python@v5
39
+ with:
40
+ python-version: ${{ matrix.python }}
41
+ allow-prereleases: true
42
+ - run: python -m pip install --upgrade pip
43
+ - run: pip install -e ".[dev]"
44
+ - run: python -m pytest -q
45
+ - name: End-to-end script
46
+ run: python scripts/e2e.py --rows 50000
47
+
48
+ minimum-versions:
49
+ name: test (oldest supported dependencies)
50
+ runs-on: ubuntu-latest
51
+ steps:
52
+ - uses: actions/checkout@v4
53
+ - uses: actions/setup-python@v5
54
+ with:
55
+ python-version: "3.10"
56
+ - run: pip install -c ci/constraints-min.txt -e . pytest numpy pandas polars duckdb mcp
57
+ - run: python -m pytest -q
58
+
59
+ build:
60
+ runs-on: ubuntu-latest
61
+ steps:
62
+ - uses: actions/checkout@v4
63
+ - uses: actions/setup-python@v5
64
+ with:
65
+ python-version: "3.13"
66
+ - run: pip install build twine
67
+ - run: python -m build
68
+ - run: twine check --strict dist/*
69
+ - name: Install the wheel in a clean environment and import it
70
+ run: |
71
+ python -m venv /tmp/clean
72
+ /tmp/clean/bin/pip install dist/*.whl polars
73
+ cd /tmp && /tmp/clean/bin/python -c "import pyursa as pu; print(pu.__version__, pu.from_dict({'a': [1]}).count())"
74
+ - uses: actions/upload-artifact@v4
75
+ with:
76
+ name: dist
77
+ path: dist/
@@ -0,0 +1,41 @@
1
+ name: Release
2
+
3
+ # Publishes to PyPI when a GitHub release is published, using PyPI trusted publishing
4
+ # (no API token stored in the repository). Configure the "pypi" environment and the
5
+ # trusted publisher on PyPI first: https://docs.pypi.org/trusted-publishers/
6
+
7
+ on:
8
+ release:
9
+ types: [published]
10
+
11
+ permissions:
12
+ contents: read
13
+
14
+ jobs:
15
+ build:
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ - uses: actions/setup-python@v5
20
+ with:
21
+ python-version: "3.13"
22
+ - run: pip install build twine
23
+ - run: python -m build
24
+ - run: twine check --strict dist/*
25
+ - uses: actions/upload-artifact@v4
26
+ with:
27
+ name: dist
28
+ path: dist/
29
+
30
+ publish:
31
+ needs: build
32
+ runs-on: ubuntu-latest
33
+ environment: pypi
34
+ permissions:
35
+ id-token: write
36
+ steps:
37
+ - uses: actions/download-artifact@v4
38
+ with:
39
+ name: dist
40
+ path: dist/
41
+ - uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,18 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ venv/
5
+ dist/
6
+ build/
7
+ *.egg-info/
8
+ .pytest_cache/
9
+ .ruff_cache/
10
+ .mypy_cache/
11
+ .coverage
12
+ htmlcov/
13
+ site/
14
+ .env
15
+ .DS_Store
16
+ *.parquet
17
+ !tests/data/*.parquet
18
+ llm_cache*.sqlite
@@ -0,0 +1,153 @@
1
+ # Changelog
2
+
3
+ All notable changes are documented here. The format follows
4
+ [Keep a Changelog](https://keepachangelog.com/) and versions follow [SemVer](https://semver.org/).
5
+
6
+ ## [1.0.0rc5] - 2026-10-20
7
+
8
+ ### Fixed
9
+ - Rate limits (HTTP 429): pyursa now waits as long as the provider asks (Google's `retryDelay` / "retry in Ns",
10
+ as well as `Retry-After`); a used-up daily quota fails at once instead of retrying for over a minute, with a
11
+ hint that the provider's quota, not pyursa, is the cause. `scripts/e2e.py` reports a provider quota as SKIP.
12
+ - Provider error messages wrapped in a list (Gemini's OpenAI layer) or in `detail`/`errors` fields were
13
+ shown as a bare "Bad Request"; the provider's real message is now extracted.
14
+ - Bad-key errors reported as HTTP 400 (xAI, Gemini) now get the "check your API key" hint.
15
+ - `scripts/check_providers.py`: probes with real public model ids, says "needs settings" when an
16
+ account ID or workspace is missing, recognizes bad-key replies of any status, treats "model not found"
17
+ or "model retired" (HTTP 410) as a reachable endpoint, and checks that a local port really serves an OpenAI-compatible API.
18
+
19
+ ## [1.0.0rc4] - 2026-10-20
20
+
21
+ ### Added
22
+ - Bedrock accepts AWS access keys without any SDK: `AWS_ACCESS_KEY_ID` / `AWS_SECRET_ACCESS_KEY`
23
+ (and `AWS_SESSION_TOKEN`), or `aws_access_key_id=` / `aws_secret_access_key=` / `aws_session_token=`.
24
+ Requests are signed with AWS Signature V4 using the standard library; signatures are tested
25
+ byte-for-byte against botocore. Works for `bedrock:` (Nova, Claude on AWS) and `bedrock-openai:`.
26
+ - `profile=` for named AWS profiles (through boto3).
27
+
28
+ ## [1.0.0rc3] - 2026-10-20
29
+
30
+ ### Added
31
+ - **53 OpenAI-compatible providers**, each checked against official docs: model vendors (OpenAI, Gemini,
32
+ Mistral, Cohere, Meta, xAI, DeepSeek, Qwen/DashScope, Kimi, GLM, MiniMax, Perplexity, AI21, Reka, Upstage),
33
+ hosts (Groq, Together, Fireworks, Cerebras, SambaNova, DeepInfra, Nebius, Novita, Baseten, OpenRouter,
34
+ Hugging Face, NVIDIA, Scaleway, OVHcloud), clouds (Azure, Vertex AI, Bedrock OpenAI, Databricks, Snowflake,
35
+ Cloudflare, Oracle OCI), gateways (LiteLLM, Portkey, Vercel, Helicone, Cloudflare AI Gateway) and local servers
36
+ (Ollama, LM Studio, vLLM, llama.cpp, LocalAI, Jan, TGI, SGLang, KoboldCpp, GPT4All).
37
+ - `openai-compatible:` catch-all using `OPENAI_BASE_URL` / `OPENAI_API_KEY`.
38
+ - Auth styles (Bearer, custom headers, Google OAuth with refresh), URL settings from environment variables
39
+ or keyword arguments, alternative key variables, `pu.print_providers()`, `scripts/check_providers.py`,
40
+ generated `docs/providers.md`.
41
+ - Automatic `max_tokens` / `max_completion_tokens` negotiation.
42
+ - Clear messages for retired services (GitHub Models, Hyperbolic, Lambda, Meta Llama API).
43
+
44
+ ### Fixed
45
+ - Together AI's base URL moved to api.together.ai; DeepSeek's documented base URL is api.deepseek.com.
46
+ - Default output limit lowered from 8192 to 4096 tokens, within every provider's cap.
47
+
48
+ ## [1.0.0rc2] - 2026-10-20
49
+
50
+ ### Added
51
+ - `claude:` provider: Claude through Anthropic's OpenAI-compatible endpoint (no SDK). `anthropic:` falls
52
+ back to it automatically when the `anthropic` package isn't installed.
53
+ - `bedrock:` works with just a Bedrock API key (`AWS_BEARER_TOKEN_BEDROCK`) over HTTPS, no boto3 needed;
54
+ covers Amazon Nova and Claude on AWS. Region from `AWS_REGION` or `region=`. Clear hints for
55
+ inference-profile ids and model access.
56
+ - `bedrock-openai:` (Bedrock's OpenAI-compatible endpoint, for gpt-oss, Qwen, DeepSeek) with a guard that
57
+ redirects Nova/Claude/Llama to `bedrock:`; `litellm:` gateway preset; `headers=` on
58
+ `OpenAICompatibleClient`; `pu.list_providers()`.
59
+
60
+ ### Changed
61
+ - Bedrock default `max_tokens` is 4096 (fits every Nova model).
62
+
63
+ ## [1.0.0rc1] - 2026-10-18
64
+
65
+ Release candidate for 1.0. The public API described in `docs/stability.md` is frozen
66
+ unless release-candidate feedback finds a problem.
67
+
68
+ ### Added
69
+ - **Types:** exact `Decimal(p, s)` with defined arithmetic scales; time-zone-aware
70
+ `Datetime(tz)` with local-time `.dt` parts; `List`/`Struct` pass-through; dictionary
71
+ columns decode to `String`; type strings such as `"Decimal(12,2)"`.
72
+ - **Expressions:** `when/then/otherwise`, `fill_null`, `coalesce`, `is_between`, `abs`,
73
+ `round` (half away from zero), string functions (`contains_regex`, `ends_with`, `strip`,
74
+ `len`, `replace`, `slice`), date functions (`year`…`second`, `weekday`, `date`, `truncate`).
75
+ - **Aggregations:** `median`, `quantile`, `std`, `var`, `any`, `all`.
76
+ - **Window functions:** aggregations `.over(partition)`, `row_number`, `rank`, dense rank,
77
+ `cum_sum`, `shift`, with deterministic tie order.
78
+ - **Operations:** full, semi and anti joins; `distinct`; `concat`.
79
+ - **I/O:** `write_parquet`, `write_csv`, `write_json`; `read_json`; multi-file, glob and
80
+ directory Parquet scans; `read_csv(schema=..., delimiter=...)`.
81
+ - **LLM:** providers for OpenAI-compatible APIs (GPT, Gemini, Groq, Together, Mistral,
82
+ DeepSeek, xAI, OpenRouter, Ollama, LM Studio, vLLM) and Bedrock (Amazon Nova);
83
+ token usage and cost reports; token budgets; PII redaction; per-session LLM settings.
84
+ - **MCP:** per-client session isolation (stdio and HTTP), `--host/--port`,
85
+ `--redact-pii`, `--llm-price`, `--llm-max-input-tokens`, `drop_frame` tool.
86
+ - **Tools:** `distinct` and `concat` steps; glob/directory/JSON loading inside the sandbox;
87
+ `preview` returns exact numbers and JSON rows.
88
+ - Agent benchmark harness (`benchmarks/agent_bench.py`), API reference generator,
89
+ docs site, CI matrix, security policy, Apache-2.0 license.
90
+
91
+ ### Changed
92
+ - Renamed from the working name `agentframe` to **pyursa** (`import pyursa as pu`, `pyursa-mcp`,
93
+ `PyursaError`, reserved prefix `__pu_`).
94
+ - Casts follow a strict contract: invalid text, non-whole floats to Int64, and casts without a
95
+ single meaning now raise errors (see docs/types.md).
96
+ - `DType` is now a class (constants such as `pu.Int64` are unchanged).
97
+ - DuckDB backend binds every user value as a query parameter.
98
+ - DuckDB backend skips ordering work when a later step makes order irrelevant
99
+ (about 2.3× faster on the end-to-end pipeline).
100
+ - CSV empty fields are read as null by default (`empty_as_null=False` restores `""`).
101
+
102
+ ### Fixed (independent pre-release review)
103
+ - DuckDB resolved columns differing only by case (`A`, `a`) to the same column; such names are now rejected.
104
+ - Paths containing `[`, `*` or `?` were globbed again after the sandbox check, which could read other files.
105
+ - Engine panics (Rust `PanicException`) could escape `ToolSession` instead of returning an error.
106
+ - Polars wrapped around on Int64 overflow; overflow now raises `INTEGER_OVERFLOW` on every engine.
107
+ - Decimal literals written with an exponent (`1E+3`) lost the exponent on DuckDB.
108
+ - Casts behaved differently per engine (float→int truncation vs rounding, text parsing); one strict
109
+ cast contract now applies everywhere, with `CAST_FAILED` errors.
110
+ - NaN handling differed between engines and between DuckDB's in-memory and Parquet paths; NaN is
111
+ now the largest value and equal to itself everywhere.
112
+ - Hour truncation of zoned datetimes on DuckDB was wrong across a DST fall-back.
113
+ - Columns named with the internal `__pu_` prefix broke results; the prefix is now reserved.
114
+ - Malformed LLM answers could crash a step; they now become null failures. Large integer answers are exact.
115
+ - `is_in` failed on Polars for mixed numeric types; `is_in([])` of null now returns null everywhere.
116
+ - Null-typed columns failed on DuckDB.
117
+ - Several error `fix` snippets didn't work when pasted; literal values now print in parseable form.
118
+ - Bad tool arguments returned `INTERNAL_ERROR`; they now return `BAD_ARGUMENTS`. More inputs are
119
+ validated when the plan is built (`head` bounds, `rename` values, `checkout` ids, token budgets).
120
+ - Fixed-offset time zones (`+05:00`) failed on DuckDB; whole-hour offsets map to `Etc/GMT` zones.
121
+ - Zoned literals at nonexistent local times (DST gaps) failed on Polars.
122
+ - (Second review round) Engines expanded glob characters in already-resolved file paths, so a
123
+ sandboxed `data[1]/a.parquet` could read `data1/a.parquet`; files are now read literally.
124
+ - (Second review round) DuckDB's optimizer could drop the overflow check when an Int64 result fed a
125
+ comparison; overflow is now checked explicitly.
126
+ - (Second review round) std/var failed on DuckDB when a NaN was present; text casts disagreed on
127
+ `24:00`, leap seconds, year 0000 and rounding that adds a digit; non-portable regex (lookaround,
128
+ backreferences) is now rejected when the plan is built; error codes no longer depend on column names;
129
+ different `FunctionClient` functions no longer share cached answers; a literal file name such as
130
+ `x[1].parquet` is no longer treated as a pattern.
131
+
132
+ ### Fixed
133
+ - Polars truncated decimal products (`1.15 × 1.15 → 1.32`); results are now exact everywhere.
134
+ - Previews rounded floats to 4 significant digits.
135
+ - Instruction-like text was only flagged when it appeared in displayed values; the whole
136
+ column is now scanned.
137
+ - String values containing NUL bytes broke DuckDB queries.
138
+ - Dates loaded from a persistent LLM cache came back as strings.
139
+ - `frame.agg()` and `select()` didn't accept keyword names.
140
+ - Some parser failures surfaced as raw Python exceptions instead of structured errors.
141
+
142
+ ## [0.4.0] - 2026-10-18
143
+ - Multi-provider LLM clients; `pu.llm_client("provider:model")`.
144
+
145
+ ## [0.3.0] - 2026-10-18
146
+ - `llm_filter`, `llm_map`, `llm_extract` with dedup, batching, caching and budgets.
147
+
148
+ ## [0.2.0] - 2026-10-18
149
+ - MCP server and handle-based tool layer; safe expression parser.
150
+
151
+ ## [0.1.0] - 2026-10-18
152
+ - Initial IR, Polars and DuckDB backends, structured errors, history, lineage,
153
+ explain, `describe_for_llm`.
@@ -0,0 +1,31 @@
1
+ # Contributing
2
+
3
+ ## Setup
4
+
5
+ ```bash
6
+ pip install -e ".[dev]"
7
+ pytest # unit, conformance, provider and security tests
8
+ python scripts/e2e.py # end-to-end checks
9
+ ruff check src tests scripts benchmarks
10
+ ```
11
+
12
+ ## Ground rules
13
+
14
+ 1. **Every behavior is the same on every backend.** If you add an operation, add a
15
+ case with explicit expected output to `tests/test_conformance*.py`. It must pass on
16
+ all backends unchanged. If engines disagree, pick a rule, document it in
17
+ `SEMANTICS` (`backends/base.py`) and make each backend follow it.
18
+ 2. **No silent coercion.** New types or casts must refuse lossy conversions.
19
+ 3. **Errors are for agents.** Raise an `PyursaError` subclass with a stable `code`,
20
+ machine-readable `details`, and at least one `suggestion` (with a `fix` snippet
21
+ when one exists). Catch mistakes when the plan is built, not at execution.
22
+ 4. **Untrusted input.** Anything reachable from `parse.py` or `tools.py` must be safe
23
+ for hostile input. Add a case to `tests/test_security.py`.
24
+ 5. **Public API changes** follow the stability policy in `docs/stability.md` and get a
25
+ `CHANGELOG.md` entry.
26
+
27
+ ## Adding a backend
28
+
29
+ Subclass `pyursa.backends.Backend`, implement `compile(node)` and
30
+ `_run(node) -> pyarrow.Table`, register it with `pu.register_backend`, and add its
31
+ name to `BACKENDS` in `tests/conftest.py`. It is done when the conformance suites pass.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
pyursa-1.0.0rc5/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ pyursa
2
+ Copyright 2026 The pyursa authors
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (see LICENSE).
@@ -0,0 +1,140 @@
1
+ Metadata-Version: 2.5
2
+ Name: pyursa
3
+ Version: 1.0.0rc5
4
+ Summary: Engine-agnostic dataframes for agentic AI: strict types, identical results on Polars and DuckDB, structured errors, undo, lineage, LLM operators and an MCP server.
5
+ Project-URL: Homepage, https://github.com/karawash-projects/pyursa
6
+ Project-URL: Documentation, https://github.com/karawash-projects/pyursa/tree/main/docs
7
+ Project-URL: Changelog, https://github.com/karawash-projects/pyursa/blob/main/CHANGELOG.md
8
+ Project-URL: Issues, https://github.com/karawash-projects/pyursa/issues
9
+ Author: The pyursa authors
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ License-File: NOTICE
13
+ Keywords: agents,arrow,data-engineering,dataframe,duckdb,llm,mcp,polars
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Programming Language :: Python :: 3.14
25
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
26
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
27
+ Classifier: Typing :: Typed
28
+ Requires-Python: >=3.10
29
+ Requires-Dist: pyarrow>=15
30
+ Provides-Extra: all
31
+ Requires-Dist: duckdb>=1.2; extra == 'all'
32
+ Requires-Dist: polars>=1.30; extra == 'all'
33
+ Provides-Extra: bedrock
34
+ Requires-Dist: boto3>=1.34; extra == 'bedrock'
35
+ Provides-Extra: dev
36
+ Requires-Dist: botocore; extra == 'dev'
37
+ Requires-Dist: build; extra == 'dev'
38
+ Requires-Dist: duckdb>=1.2; extra == 'dev'
39
+ Requires-Dist: mcp>=1.21.1; extra == 'dev'
40
+ Requires-Dist: numpy; extra == 'dev'
41
+ Requires-Dist: pandas; extra == 'dev'
42
+ Requires-Dist: polars>=1.30; extra == 'dev'
43
+ Requires-Dist: pytest>=8; extra == 'dev'
44
+ Requires-Dist: ruff; extra == 'dev'
45
+ Requires-Dist: twine; extra == 'dev'
46
+ Provides-Extra: duckdb
47
+ Requires-Dist: duckdb>=1.2; extra == 'duckdb'
48
+ Provides-Extra: llm
49
+ Requires-Dist: anthropic>=0.40; extra == 'llm'
50
+ Provides-Extra: mcp
51
+ Requires-Dist: duckdb>=1.2; extra == 'mcp'
52
+ Requires-Dist: mcp>=1.21.1; extra == 'mcp'
53
+ Requires-Dist: polars>=1.30; extra == 'mcp'
54
+ Provides-Extra: polars
55
+ Requires-Dist: polars>=1.30; extra == 'polars'
56
+ Description-Content-Type: text/markdown
57
+
58
+ # pyursa
59
+
60
+ **Engine-agnostic dataframes for the agentic AI era.** Named for *Ursa*, the bear, in the
61
+ tradition of pandas and Polars. One strict, lazy API runs on
62
+ Polars or DuckDB with identical results. The plan layer adds what AI agents need:
63
+ structured errors with fixes, undo, lineage, dry runs, token-budgeted summaries,
64
+ LLM-powered operators, and an MCP server.
65
+
66
+ ```python
67
+ import pyursa as pu
68
+ from pyursa import col
69
+
70
+ orders = pu.read_parquet("orders/*.parquet") # lazy
71
+ print(orders.describe_for_llm(tokens=500)) # fits an LLM context window
72
+
73
+ report = (orders
74
+ .filter(col("qty") > 0, col("status") != "cancelled", intent="valid orders only")
75
+ .with_columns(revenue=col("qty") * col("price"))
76
+ .group_by("region")
77
+ .agg(revenue=col("revenue").sum(), orders=pu.len(), p90=col("price").quantile(0.9))
78
+ .sort("revenue", descending=True))
79
+
80
+ report.explain() # dry run: schema, size bounds, compiled query
81
+ report.collect("duckdb") # pyarrow.Table, identical on "polars"
82
+ report.undo(2); report.lineage("revenue"); report.write_parquet("report.parquet")
83
+ ```
84
+
85
+ ```python
86
+ orders.filter(col("quantity") > "5")
87
+ # [COLUMN_NOT_FOUND] Column 'quantity' not found in the input of this step.
88
+ # suggestion: Did you mean 'qty'? -> col("qty")
89
+ ```
90
+
91
+ ## Install
92
+
93
+ ```bash
94
+ pip install "pyursa[all]" # Polars + DuckDB backends
95
+ pip install "pyursa[mcp]" # + MCP server (pyursa-mcp)
96
+ ```
97
+
98
+ Python 3.10+. From a source checkout: `pip install -e ".[dev]"`.
99
+
100
+ ## Highlights
101
+
102
+ - **Same answers on every engine.** One semantics contract (nulls, NaN, sort stability,
103
+ rounding, decimals, casts, overflow, quantiles, window ties) enforced by conformance tests
104
+ on every backend. Float sums may differ in the last digits; everything else is identical.
105
+ - **Strict types, no silent corruption.** Exact `Decimal(p,s)` math, time-zone-aware
106
+ `Datetime(tz)`, `List`/`Struct` pass-through, strict casts, integer overflow errors;
107
+ lossy inputs raise errors instead of corrupting data.
108
+ - **Complete toolkit.** Filters, joins (inner, left, full, semi, anti), group-by with
109
+ median/quantile/std, window functions (rank, row_number, running totals, lag), `when/then`,
110
+ string and date functions, distinct, concat, Parquet/CSV/JSON in and out.
111
+ - **Built for agents.** Errors are JSON with paste-ready fixes, raised before execution.
112
+ Immutable frames with `history()`/`undo()`, column `lineage()`, `explain()` dry runs, and
113
+ `describe_for_llm(tokens=N)` that always fits and flags prompt-injection text.
114
+ - **LLM operators.** `llm_filter`, `llm_map`, `llm_extract` with **any major LLM**: 53
115
+ OpenAI-compatible providers (OpenAI, Gemini, Mistral, Cohere, xAI, DeepSeek, Qwen, Kimi, GLM,
116
+ Groq, Together, Fireworks, Azure, Vertex, Databricks, Snowflake, Cloudflare, OpenRouter, LiteLLM,
117
+ Ollama, vLLM, ...) plus native Claude and Amazon Bedrock (Nova, Claude on AWS). Dedup, batching,
118
+ caching, row/token budgets, cost reports and PII redaction included. See [providers](docs/providers.md).
119
+ - **MCP server.** Handles instead of data, sandboxed files, a code-free expression parser,
120
+ per-client session isolation.
121
+ - **Fast.** About 3–4× pandas on a typical analysis at 2M rows (see `scripts/e2e.py`).
122
+
123
+ ## Documentation
124
+
125
+ [Guide](docs/guide.md) · [Types](docs/types.md) · [Agents and MCP](docs/agents.md) ·
126
+ [LLM operators](docs/llm.md) · [LLM providers](docs/providers.md) · [Semantics](docs/semantics.md) · [API reference](docs/api.md) ·
127
+ [Security](SECURITY.md) · [Stability policy](docs/stability.md) · [Changelog](CHANGELOG.md)
128
+
129
+ ## Testing
130
+
131
+ ```bash
132
+ pytest # unit, conformance, provider and security tests
133
+ python scripts/e2e.py # end-to-end checks, including pandas comparison
134
+ python scripts/e2e.py --llm gemini:<model> # live LLM check with any provider
135
+ python benchmarks/agent_bench.py --llm gemini:<model> --allow-code-exec # agent benchmark
136
+ ```
137
+
138
+ ## License
139
+
140
+ Apache-2.0. See [LICENSE](LICENSE).