nlp2sql 0.2.0rc11__tar.gz → 0.2.0rc13__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.
- nlp2sql-0.2.0rc13/PKG-INFO +418 -0
- nlp2sql-0.2.0rc13/README.md +340 -0
- nlp2sql-0.2.0rc13/docker/init-schema.sql +313 -0
- nlp2sql-0.2.0rc13/docs/API.md +425 -0
- nlp2sql-0.2.0rc13/docs/ARCHITECTURE.md +366 -0
- nlp2sql-0.2.0rc13/docs/CONFIGURATION.md +269 -0
- nlp2sql-0.2.0rc13/docs/ENTERPRISE.md +244 -0
- nlp2sql-0.2.0rc13/docs/Redshift.md +166 -0
- nlp2sql-0.2.0rc13/examples/README.md +155 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/pyproject.toml +1 -1
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/__init__.py +101 -16
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/adapters/anthropic_adapter.py +31 -1
- nlp2sql-0.2.0rc13/src/nlp2sql/adapters/default_error_classifier.py +65 -0
- nlp2sql-0.2.0rc13/src/nlp2sql/adapters/default_repair_policy.py +41 -0
- nlp2sql-0.2.0rc13/src/nlp2sql/adapters/dict_semantic_resolver.py +27 -0
- nlp2sql-0.2.0rc13/src/nlp2sql/adapters/file_semantic_resolver.py +24 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/adapters/gemini_adapter.py +31 -1
- nlp2sql-0.2.0rc13/src/nlp2sql/adapters/noop_semantic_resolver.py +20 -0
- nlp2sql-0.2.0rc13/src/nlp2sql/adapters/noop_semantic_validator.py +19 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/adapters/openai_adapter.py +31 -1
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/adapters/openai_embedding_adapter.py +10 -7
- nlp2sql-0.2.0rc13/src/nlp2sql/adapters/schema_repository_execution_adapter.py +20 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/cli.py +150 -19
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/client.py +57 -2
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/config/settings.py +2 -1
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/core/database_prompts.py +3 -1
- nlp2sql-0.2.0rc13/src/nlp2sql/core/entities.py +332 -0
- nlp2sql-0.2.0rc13/src/nlp2sql/core/runtime.py +39 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/ports/ai_provider.py +1 -1
- nlp2sql-0.2.0rc13/src/nlp2sql/ports/error_classifier.py +19 -0
- nlp2sql-0.2.0rc13/src/nlp2sql/ports/query_execution.py +16 -0
- nlp2sql-0.2.0rc13/src/nlp2sql/ports/repair_policy.py +19 -0
- nlp2sql-0.2.0rc13/src/nlp2sql/ports/semantic_resolver.py +22 -0
- nlp2sql-0.2.0rc13/src/nlp2sql/ports/semantic_validator.py +21 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/schema/example_store.py +54 -15
- nlp2sql-0.2.0rc13/src/nlp2sql/services/example_selection_service.py +188 -0
- nlp2sql-0.2.0rc13/src/nlp2sql/services/prompt_assembly_service.py +64 -0
- nlp2sql-0.2.0rc13/src/nlp2sql/services/query_analysis_service.py +231 -0
- nlp2sql-0.2.0rc13/src/nlp2sql/services/query_repair_service.py +62 -0
- nlp2sql-0.2.0rc13/src/nlp2sql/services/query_service.py +653 -0
- nlp2sql-0.2.0rc13/src/nlp2sql/services/semantic_resolution_service.py +195 -0
- nlp2sql-0.2.0rc13/src/nlp2sql/services/semantic_validation_service.py +161 -0
- nlp2sql-0.2.0rc13/src/nlp2sql/services/sql_intent_planning_service.py +136 -0
- nlp2sql-0.2.0rc13/src/nlp2sql/utils/artifact_loader.py +202 -0
- nlp2sql-0.2.0rc13/src/nlp2sql/utils/semantic_prompt.py +186 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/tests/conftest.py +11 -1
- nlp2sql-0.2.0rc13/tests/test_artifact_loader.py +65 -0
- nlp2sql-0.2.0rc13/tests/test_cli_semantic_support.py +138 -0
- nlp2sql-0.2.0rc13/tests/test_client_hooks.py +160 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/tests/test_database_prompts.py +3 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/tests/test_dsl_integration.py +174 -3
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/tests/test_postgres_integration.py +51 -1
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/tests/test_redshift_integration.py +2 -2
- nlp2sql-0.2.0rc13/tests/test_retrieval_pipeline.py +489 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/uv.lock +1 -1
- nlp2sql-0.2.0rc11/PKG-INFO +0 -342
- nlp2sql-0.2.0rc11/README.md +0 -264
- nlp2sql-0.2.0rc11/docker/init-schema.sql +0 -160
- nlp2sql-0.2.0rc11/docs/API.md +0 -385
- nlp2sql-0.2.0rc11/docs/ARCHITECTURE.md +0 -319
- nlp2sql-0.2.0rc11/docs/CONFIGURATION.md +0 -175
- nlp2sql-0.2.0rc11/docs/ENTERPRISE.md +0 -407
- nlp2sql-0.2.0rc11/docs/Redshift.md +0 -208
- nlp2sql-0.2.0rc11/examples/README.md +0 -168
- nlp2sql-0.2.0rc11/src/nlp2sql/core/entities.py +0 -92
- nlp2sql-0.2.0rc11/src/nlp2sql/services/query_service.py +0 -354
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/.claude/commands/db.md +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/.claude/commands/quality.md +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/.claude/commands/test.md +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/.claude/rules/adapters.md +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/.claude/rules/architecture.md +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/.claude/rules/python-style.md +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/.claude/rules/testing.md +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/.claude/settings.json +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/.github/workflows/ci.yml +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/.github/workflows/publish-pypi.yml +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/.github/workflows/publish-testpypi.yml +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/.gitignore +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/.mcp.json.example +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/.python-version +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/CLAUDE.md +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/CONTRIBUTING.md +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/LICENSE +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/SECURITY.md +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/assets/nlp2sql-logo.png +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/benchmarks/enterprise_benchmark_results.json +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/docker/.env.example +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/docker/README.md +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/docker/docker-compose.yml +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/docker/get-db-urls.sh +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/docker/large-schema.sql +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/docker/localstack-init.sh +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/docker/test-redshift.sh +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/advanced/test_multiple_providers.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/advanced/test_simple_api.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/database_specific/test_odoo_integration.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/default_examples.json +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/documentation/real_world_example.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/getting_started/basic_usage.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/getting_started/simple_demo.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/getting_started/test_api_setup.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/schema_management/test_auto_schema.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/schema_management/test_schema_filters_comprehensive.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/strands-fastapi-agent/.dockerignore +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/strands-fastapi-agent/.env.example +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/strands-fastapi-agent/DOCKER_README.md +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/strands-fastapi-agent/DOCKER_SETUP.md +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/strands-fastapi-agent/DOCKER_TESTING_SUMMARY.md +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/strands-fastapi-agent/Dockerfile +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/strands-fastapi-agent/INDEX.md +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/strands-fastapi-agent/README.md +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/strands-fastapi-agent/docker/init-ecommerce-schema.sql +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/strands-fastapi-agent/docker-compose.yml +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/strands-fastapi-agent/main.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/strands-fastapi-agent/pyproject.toml +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/examples/strands-fastapi-agent/test-docker-endpoints.sh +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/install-dev.sh +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/mcp_server/README.md +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/mcp_server/__init__.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/mcp_server/example_config.json +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/mcp_server/pyproject.toml +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/mcp_server/server.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/adapters/__init__.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/adapters/local_embedding_adapter.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/adapters/postgres_repository.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/adapters/redshift_adapter.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/adapters/regex_query_validator.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/config/__init__.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/core/__init__.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/core/provider_config.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/core/result.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/core/sql_keywords.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/core/sql_safety.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/exceptions/__init__.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/factories/__init__.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/factories/repository_factory.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/ports/__init__.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/ports/cache.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/ports/embedding_provider.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/ports/example_repository.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/ports/query_optimizer.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/ports/query_safety.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/ports/query_validator.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/ports/schema_repository.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/ports/schema_strategy.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/schema/__init__.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/schema/analyzer.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/schema/embedding_manager.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/schema/example_loader.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/schema/manager.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/services/__init__.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/utils/__init__.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/utils/helpers.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/src/nlp2sql/utils/storage.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/test_tmp/.gitignore +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/tests/mcp/__init__.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/tests/mcp/test_sql_security.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/tests/test_basic.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/tests/test_batch_scoring.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/tests/test_column_validation.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/tests/test_embedding_manager.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/tests/test_integration.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/tests/test_repository_cache.py +0 -0
- {nlp2sql-0.2.0rc11 → nlp2sql-0.2.0rc13}/tests/test_repository_factory.py +0 -0
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nlp2sql
|
|
3
|
+
Version: 0.2.0rc13
|
|
4
|
+
Summary: Enterprise-ready Natural Language to SQL converter with multi-provider support. Built for production scale (1000+ tables) with Clean Architecture.
|
|
5
|
+
Project-URL: Homepage, https://github.com/luiscarbonel1991/nlp2sql
|
|
6
|
+
Project-URL: Bug Tracker, https://github.com/luiscarbonel1991/nlp2sql/issues
|
|
7
|
+
Project-URL: Documentation, https://nlp2sql.readthedocs.io
|
|
8
|
+
Author-email: luiscarbonel1991 <devhighlevel@gmail.com>
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: ai,clean-architecture,database,enterprise,llm,multi-provider,mysql,natural-language,nlp,postgres,production,query-generation,schema-filtering,sql
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Database
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Requires-Python: >=3.9
|
|
24
|
+
Requires-Dist: anthropic>=0.18.0
|
|
25
|
+
Requires-Dist: azure-identity>=1.15.0
|
|
26
|
+
Requires-Dist: boto3>=1.34.0
|
|
27
|
+
Requires-Dist: click>=8.0.0
|
|
28
|
+
Requires-Dist: faiss-cpu>=1.7.4
|
|
29
|
+
Requires-Dist: google-generativeai>=0.3.0
|
|
30
|
+
Requires-Dist: greenlet>=3.2.3
|
|
31
|
+
Requires-Dist: httpx>=0.25.0
|
|
32
|
+
Requires-Dist: numpy>=1.24.0
|
|
33
|
+
Requires-Dist: openai>=1.0.0
|
|
34
|
+
Requires-Dist: pandas>=2.0.0
|
|
35
|
+
Requires-Dist: psycopg2-binary>=2.9.0
|
|
36
|
+
Requires-Dist: psycopg[binary]>=3.2.13
|
|
37
|
+
Requires-Dist: pydantic-settings>=2.0.0
|
|
38
|
+
Requires-Dist: pydantic>=2.5.0
|
|
39
|
+
Requires-Dist: redis>=5.0.0
|
|
40
|
+
Requires-Dist: scikit-learn>=1.3.0
|
|
41
|
+
Requires-Dist: sqlalchemy-redshift>=0.7.0
|
|
42
|
+
Requires-Dist: sqlalchemy>=2.0.0
|
|
43
|
+
Requires-Dist: structlog>=24.1.0
|
|
44
|
+
Requires-Dist: tenacity>=8.2.0
|
|
45
|
+
Requires-Dist: tiktoken>=0.5.0
|
|
46
|
+
Provides-Extra: all-embeddings
|
|
47
|
+
Requires-Dist: sentence-transformers>=2.5.0; extra == 'all-embeddings'
|
|
48
|
+
Provides-Extra: all-providers
|
|
49
|
+
Requires-Dist: anthropic>=0.18.0; extra == 'all-providers'
|
|
50
|
+
Requires-Dist: google-generativeai>=0.3.0; extra == 'all-providers'
|
|
51
|
+
Provides-Extra: anthropic
|
|
52
|
+
Requires-Dist: anthropic>=0.18.0; extra == 'anthropic'
|
|
53
|
+
Provides-Extra: dev
|
|
54
|
+
Requires-Dist: black>=23.7.0; extra == 'dev'
|
|
55
|
+
Requires-Dist: isort>=5.12.0; extra == 'dev'
|
|
56
|
+
Requires-Dist: mypy>=1.7.0; extra == 'dev'
|
|
57
|
+
Requires-Dist: myst-parser>=2.0.0; extra == 'dev'
|
|
58
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
59
|
+
Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
|
|
60
|
+
Requires-Dist: pytest-mock>=3.11.0; extra == 'dev'
|
|
61
|
+
Requires-Dist: pytest>=7.4.0; extra == 'dev'
|
|
62
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
63
|
+
Requires-Dist: sphinx-rtd-theme>=1.3.0; extra == 'dev'
|
|
64
|
+
Requires-Dist: sphinx>=7.0.0; extra == 'dev'
|
|
65
|
+
Provides-Extra: embeddings-local
|
|
66
|
+
Requires-Dist: sentence-transformers>=2.5.0; extra == 'embeddings-local'
|
|
67
|
+
Provides-Extra: embeddings-openai
|
|
68
|
+
Provides-Extra: gemini
|
|
69
|
+
Requires-Dist: google-generativeai>=0.3.0; extra == 'gemini'
|
|
70
|
+
Provides-Extra: mssql
|
|
71
|
+
Requires-Dist: pymssql>=2.2.0; extra == 'mssql'
|
|
72
|
+
Provides-Extra: mysql
|
|
73
|
+
Requires-Dist: mysql-connector-python>=8.0.0; extra == 'mysql'
|
|
74
|
+
Requires-Dist: pymysql>=1.1.0; extra == 'mysql'
|
|
75
|
+
Provides-Extra: oracle
|
|
76
|
+
Requires-Dist: oracledb>=2.0.0; extra == 'oracle'
|
|
77
|
+
Description-Content-Type: text/markdown
|
|
78
|
+
|
|
79
|
+
<p align="center">
|
|
80
|
+
<img src="assets/nlp2sql-logo.png" alt="nlp2sql logo" width="400">
|
|
81
|
+
</p>
|
|
82
|
+
|
|
83
|
+
<p align="center">
|
|
84
|
+
<a href="https://pepy.tech/projects/nlp2sql"><img src="https://static.pepy.tech/personalized-badge/nlp2sql?period=total&units=INTERNATIONAL_SYSTEM&left_color=BLACK&right_color=GREEN&left_text=downloads" alt="PyPI Downloads"></a>
|
|
85
|
+
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
|
|
86
|
+
<a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.9+-blue.svg" alt="Python 3.9+"></a>
|
|
87
|
+
<a href="https://github.com/psf/black"><img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Code style: black"></a>
|
|
88
|
+
</p>
|
|
89
|
+
|
|
90
|
+
# nlp2sql
|
|
91
|
+
|
|
92
|
+
**DSL-first natural language to SQL for PostgreSQL and Redshift**
|
|
93
|
+
|
|
94
|
+
`nlp2sql` turns a natural language question into SQL through a reusable Python DSL:
|
|
95
|
+
|
|
96
|
+
- `await connect(...)`
|
|
97
|
+
- `await nlp.ask(...)`
|
|
98
|
+
- optional few-shot examples
|
|
99
|
+
- optional semantic context
|
|
100
|
+
- optional validation and repair
|
|
101
|
+
|
|
102
|
+
The library is designed for both simple schemas and large warehouses, but all public examples in this repository use the local e-commerce domain shipped with the project itself.
|
|
103
|
+
|
|
104
|
+
## Features
|
|
105
|
+
|
|
106
|
+
- **DSL-first API**: `connect()` returns an `NLP2SQL` client with `ask()`, `validate()`, `explain()`, and `suggest()`
|
|
107
|
+
- **Business-aware generation**: optional `SemanticContext` adds canonical tables, metrics, dimensions, rules, and mappings
|
|
108
|
+
- **Execution modes**: generate only, generate plus validate, and generate plus validate plus repair
|
|
109
|
+
- **Few-shot examples**: pass example lists directly or use an example repository implementation
|
|
110
|
+
- **Large schema support**: FAISS plus TF-IDF hybrid retrieval, schema filters, and disk-backed caches
|
|
111
|
+
- **Multiple providers**: OpenAI, Anthropic, and Gemini
|
|
112
|
+
- **Database support**: PostgreSQL and Amazon Redshift
|
|
113
|
+
- **Async by default**: built for services, APIs, notebooks, and workers
|
|
114
|
+
|
|
115
|
+
## Documentation
|
|
116
|
+
|
|
117
|
+
| Document | Description |
|
|
118
|
+
|----------|-------------|
|
|
119
|
+
| [Architecture](docs/ARCHITECTURE.md) | Runtime flow, services, ports, and diagrams |
|
|
120
|
+
| [API Reference](docs/API.md) | Python API, CLI, hooks, and metadata reference |
|
|
121
|
+
| [Configuration](docs/CONFIGURATION.md) | Environment variables, examples, semantic context, cache behavior |
|
|
122
|
+
| [Enterprise Guide](docs/ENTERPRISE.md) | Governed usage, scale, and deployment patterns |
|
|
123
|
+
| [Redshift Support](docs/Redshift.md) | Redshift-specific notes using public examples |
|
|
124
|
+
| [Examples](examples/README.md) | Safe public examples based on the local e-commerce domain |
|
|
125
|
+
| [Contributing](CONTRIBUTING.md) | Contribution guidelines |
|
|
126
|
+
|
|
127
|
+
## Installation
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
# With UV (recommended)
|
|
131
|
+
uv add nlp2sql
|
|
132
|
+
|
|
133
|
+
# With pip
|
|
134
|
+
pip install nlp2sql
|
|
135
|
+
|
|
136
|
+
# With specific providers
|
|
137
|
+
pip install nlp2sql[anthropic,gemini]
|
|
138
|
+
pip install nlp2sql[all-providers]
|
|
139
|
+
|
|
140
|
+
# With embeddings
|
|
141
|
+
pip install nlp2sql[embeddings-local]
|
|
142
|
+
pip install nlp2sql[embeddings-openai]
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Quick Start
|
|
146
|
+
|
|
147
|
+
### 1. Set a Provider Key
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
export OPENAI_API_KEY="your-openai-key"
|
|
151
|
+
# or ANTHROPIC_API_KEY / GOOGLE_API_KEY
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### 2. Use the DSL
|
|
155
|
+
|
|
156
|
+
```python
|
|
157
|
+
import asyncio
|
|
158
|
+
|
|
159
|
+
import nlp2sql
|
|
160
|
+
from nlp2sql import ProviderConfig
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
async def main():
|
|
164
|
+
nlp = await nlp2sql.connect(
|
|
165
|
+
"postgresql://testuser:testpass@localhost:5432/testdb",
|
|
166
|
+
provider=ProviderConfig(provider="openai", api_key="sk-..."),
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
result = await nlp.ask("Show active users by region")
|
|
170
|
+
print(result.sql)
|
|
171
|
+
print(result.confidence)
|
|
172
|
+
print(result.metadata["sql_intent_plan"])
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
asyncio.run(main())
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
`connect()` loads the schema, initializes retrieval indexes, and returns a reusable `NLP2SQL` client. `ask()` returns a typed `QueryResult`.
|
|
179
|
+
|
|
180
|
+
### 3. Add Few-Shot Examples
|
|
181
|
+
|
|
182
|
+
Pass examples directly to `connect()`. The library handles indexing for you.
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
nlp = await nlp2sql.connect(
|
|
186
|
+
"postgresql://testuser:testpass@localhost:5432/testdb",
|
|
187
|
+
provider=ProviderConfig(provider="openai", api_key="sk-..."),
|
|
188
|
+
examples=[
|
|
189
|
+
{
|
|
190
|
+
"question": "Show revenue by source category for the flagship store",
|
|
191
|
+
"sql": (
|
|
192
|
+
"SELECT d.metric_date, mc.source_category, SUM(d.revenue) AS revenue "
|
|
193
|
+
"FROM daily_channel_metrics d "
|
|
194
|
+
"JOIN stores s ON d.store_id = s.id "
|
|
195
|
+
"JOIN marketing_channels mc ON d.channel_id = mc.id "
|
|
196
|
+
"WHERE s.code = 'na_flagship' "
|
|
197
|
+
"GROUP BY d.metric_date, mc.source_category"
|
|
198
|
+
),
|
|
199
|
+
"database_type": "postgres",
|
|
200
|
+
}
|
|
201
|
+
],
|
|
202
|
+
)
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### 4. Add In-Memory Semantic Context
|
|
206
|
+
|
|
207
|
+
Use semantic context when the same question could map to multiple plausible tables or dimensions.
|
|
208
|
+
|
|
209
|
+
```python
|
|
210
|
+
from nlp2sql import (
|
|
211
|
+
DimensionDefinition,
|
|
212
|
+
DomainRule,
|
|
213
|
+
MetricDefinition,
|
|
214
|
+
SemanticContext,
|
|
215
|
+
SemanticEntityMapping,
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
semantic_context = SemanticContext(
|
|
219
|
+
domain="ecommerce_channel_performance",
|
|
220
|
+
canonical_tables=["daily_channel_metrics"],
|
|
221
|
+
required_filters=["s.code = 'na_flagship'", "s.region = 'North America'"],
|
|
222
|
+
entity_mappings=[
|
|
223
|
+
SemanticEntityMapping(
|
|
224
|
+
source_term="North America flagship store",
|
|
225
|
+
target="store_scope",
|
|
226
|
+
resolved_value="na_flagship / North America",
|
|
227
|
+
filter_expression="s.code = 'na_flagship' AND s.region = 'North America'",
|
|
228
|
+
)
|
|
229
|
+
],
|
|
230
|
+
metric_definitions=[
|
|
231
|
+
MetricDefinition(name="revenue", description="Revenue by day and source category."),
|
|
232
|
+
MetricDefinition(name="orders_count", description="Orders by day and source category."),
|
|
233
|
+
],
|
|
234
|
+
dimension_definitions=[
|
|
235
|
+
DimensionDefinition(name="metric_date", description="Daily grain."),
|
|
236
|
+
DimensionDefinition(name="source_category", description="Channel grouping."),
|
|
237
|
+
],
|
|
238
|
+
rules=[
|
|
239
|
+
DomainRule(
|
|
240
|
+
name="preserve_source_breakdown",
|
|
241
|
+
description="Keep source_category when the question asks for a source breakdown.",
|
|
242
|
+
required_dimensions=["source_category"],
|
|
243
|
+
preferred_tables=["daily_channel_metrics"],
|
|
244
|
+
)
|
|
245
|
+
],
|
|
246
|
+
)
|
|
247
|
+
|
|
248
|
+
result = await nlp.ask(
|
|
249
|
+
"Show daily revenue and order count by source category for the North America flagship store",
|
|
250
|
+
semantic_context=semantic_context,
|
|
251
|
+
)
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### 5. Validate and Repair
|
|
255
|
+
|
|
256
|
+
`ask()` supports execution-aware modes directly.
|
|
257
|
+
|
|
258
|
+
```python
|
|
259
|
+
result = await nlp.ask(
|
|
260
|
+
"Show revenue by source category for the flagship store",
|
|
261
|
+
validate=True,
|
|
262
|
+
repair=True,
|
|
263
|
+
)
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
- `generate_only`: generate SQL only
|
|
267
|
+
- `generate_and_validate`: execute readonly validation when execution is wired
|
|
268
|
+
- `generate_validate_repair`: retry on semantic or execution failures when repair hooks are available
|
|
269
|
+
|
|
270
|
+
### 6. CLI Parity
|
|
271
|
+
|
|
272
|
+
The CLI exposes the same concepts:
|
|
273
|
+
|
|
274
|
+
```bash
|
|
275
|
+
nlp2sql query \
|
|
276
|
+
--database-url postgresql://testuser:testpass@localhost:5432/testdb \
|
|
277
|
+
--question "Show daily revenue by source category for the North America flagship store" \
|
|
278
|
+
--examples-file examples.json \
|
|
279
|
+
--semantic-context-file semantic-context.json \
|
|
280
|
+
--validate \
|
|
281
|
+
--repair \
|
|
282
|
+
--show-semantic-context \
|
|
283
|
+
--show-sql-intent-plan \
|
|
284
|
+
--show-selected-examples
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
## How It Works
|
|
288
|
+
|
|
289
|
+
```mermaid
|
|
290
|
+
flowchart TD
|
|
291
|
+
userCode[UserCodeOrCLI] --> dsl[connectAndAskDSL]
|
|
292
|
+
dsl --> analysis[QueryAnalysisService]
|
|
293
|
+
analysis --> semantic[SemanticResolutionService]
|
|
294
|
+
semantic --> retrieval[SchemaRetrievalAndExampleSelection]
|
|
295
|
+
retrieval --> intent[SqlIntentPlanningService]
|
|
296
|
+
intent --> prompt[PromptAssemblyAndAdapters]
|
|
297
|
+
prompt --> llm[LLMGeneration]
|
|
298
|
+
llm --> semval[SemanticValidation]
|
|
299
|
+
semval --> exec[OptionalExecutionAndRepair]
|
|
300
|
+
exec --> result[QueryResultMetadata]
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
At runtime the library:
|
|
304
|
+
|
|
305
|
+
1. analyzes the question
|
|
306
|
+
2. optionally resolves and merges semantic context
|
|
307
|
+
3. retrieves relevant schema and examples
|
|
308
|
+
4. builds a structured SQL intent plan
|
|
309
|
+
5. assembles the prompt
|
|
310
|
+
6. generates SQL
|
|
311
|
+
7. optionally validates, executes, and repairs
|
|
312
|
+
8. returns a `QueryResult` with debug metadata
|
|
313
|
+
|
|
314
|
+
See [Architecture](docs/ARCHITECTURE.md) for the full breakdown.
|
|
315
|
+
|
|
316
|
+
## Public Example Domain
|
|
317
|
+
|
|
318
|
+
This repository ships a local e-commerce integration domain used in tests and docs. It includes:
|
|
319
|
+
|
|
320
|
+
- `stores`
|
|
321
|
+
- `marketing_channels`
|
|
322
|
+
- `users`
|
|
323
|
+
- `products`
|
|
324
|
+
- `orders`
|
|
325
|
+
- `order_items`
|
|
326
|
+
- `daily_channel_metrics`
|
|
327
|
+
|
|
328
|
+
The public examples intentionally stay inside that domain to avoid leaking any private warehouse schema.
|
|
329
|
+
|
|
330
|
+
To start it locally:
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
cd docker
|
|
334
|
+
docker compose up -d postgres
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
The default URL is:
|
|
338
|
+
|
|
339
|
+
```bash
|
|
340
|
+
postgresql://testuser:testpass@localhost:5432/testdb
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
## Provider Comparison
|
|
344
|
+
|
|
345
|
+
| Provider | Default Model | Context Size | Best For |
|
|
346
|
+
|----------|---------------|--------------|----------|
|
|
347
|
+
| OpenAI | `gpt-4o-mini` | 128K | Fast general purpose usage |
|
|
348
|
+
| Anthropic | `claude-sonnet-4-20250514` | 200K | Larger schemas and long prompts |
|
|
349
|
+
| Gemini | `gemini-2.0-flash` | 1M | High-volume and very large contexts |
|
|
350
|
+
|
|
351
|
+
All models are configurable through `ProviderConfig`.
|
|
352
|
+
|
|
353
|
+
## Lower-Level API
|
|
354
|
+
|
|
355
|
+
`connect()` is the recommended path. Lower-level entry points still exist for advanced wiring:
|
|
356
|
+
|
|
357
|
+
```python
|
|
358
|
+
from nlp2sql import DatabaseType, ProviderConfig, create_and_initialize_service
|
|
359
|
+
|
|
360
|
+
service = await create_and_initialize_service(
|
|
361
|
+
database_url="postgresql://testuser:testpass@localhost:5432/testdb",
|
|
362
|
+
provider_config=ProviderConfig(provider="openai", api_key="sk-..."),
|
|
363
|
+
database_type=DatabaseType.POSTGRES,
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
result = await service.generate_sql(
|
|
367
|
+
"Count active users by region",
|
|
368
|
+
database_type=DatabaseType.POSTGRES,
|
|
369
|
+
)
|
|
370
|
+
print(result["sql"])
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
## Development
|
|
374
|
+
|
|
375
|
+
```bash
|
|
376
|
+
git clone https://github.com/luiscarbonel1991/nlp2sql.git
|
|
377
|
+
cd nlp2sql
|
|
378
|
+
uv sync
|
|
379
|
+
|
|
380
|
+
# Start the local public e-commerce database
|
|
381
|
+
cd docker && docker compose up -d postgres
|
|
382
|
+
|
|
383
|
+
# Integration tests without llm
|
|
384
|
+
cd ..
|
|
385
|
+
uv run pytest -m "integration and not llm"
|
|
386
|
+
|
|
387
|
+
# Optional llm integration tests
|
|
388
|
+
uv run pytest -m "integration and llm"
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
## MCP Server
|
|
392
|
+
|
|
393
|
+
`nlp2sql` includes a Model Context Protocol server for assistant integration.
|
|
394
|
+
|
|
395
|
+
```json
|
|
396
|
+
{
|
|
397
|
+
"mcpServers": {
|
|
398
|
+
"nlp2sql": {
|
|
399
|
+
"command": "python",
|
|
400
|
+
"args": ["/path/to/nlp2sql/mcp_server/server.py"],
|
|
401
|
+
"env": {
|
|
402
|
+
"OPENAI_API_KEY": "${OPENAI_API_KEY}",
|
|
403
|
+
"NLP2SQL_DEFAULT_DB_URL": "postgresql://testuser:testpass@localhost:5432/testdb"
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
See [mcp_server/README.md](mcp_server/README.md) for details.
|
|
411
|
+
|
|
412
|
+
## Contributing
|
|
413
|
+
|
|
414
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
415
|
+
|
|
416
|
+
## License
|
|
417
|
+
|
|
418
|
+
MIT License. See [LICENSE](LICENSE).
|