Skip to main content

A modular text-to-SQL toolkit.

Project description

🐷 piglets

A modular library of text-to-SQL tools.

Status

piglets is currently an alpha-stage package. The API is expected to evolve before 1.0.

Get started

Install

venv

pip install piglets

uv

uv add piglets

Install the optional dependency for the model provider you use. For OpenAI:

venv

pip install "piglets[openai]"

uv

uv add "piglets[openai]"

Other provider extras include anthropic, google_genai, google_vertexai, bedrock, cohere, mistralai, groq, ollama, and openrouter.

Example

Use gpt-5.2 to generate 3 logical plans from a natural language query.

from piglets import LogicalPlanner

# initialise a logical planner
logical_planner = LogicalPlanner('gpt-5.2')

# generate 3 logical plan samples and aggregate them
logical_plan = logical_planner.plan(
    natural_language_query="What was the average number of piglets per week for Q4 2025?",
    num_samples=3,
)

# print the aggregated logical plan
for i, step in enumerate(logical_plan.logical_steps):
    print(f"Step {i + 1}: ")
    print(step)

# inspect the candidate plans used to create the aggregate
print(f"Aggregated from {len(logical_plan.sample_plans)} sample plans.")
>>> Step 1:
>>> 1. Identify all piglet birth (or piglet addition) events with their event dates and piglet counts.
>>> Step 2:
>>> 2. Filter the events to the Q4 2025 date range (Oct 1, 2025 through Dec 31, 2025).
>>> Step 3:
>>> 3. Assign each event to a calendar week within that quarter using a consistent week definition (e.g., week starting Monday or Sunday).
>>> Aggregated from 3 sample plans.
...

Current scope

Planning

The first included primitive is a LogicalPlanner that turns a natural-language analytics question into an ordered list of abstract logical steps. The logical planner is an implementation of the planner found in the Apex-SQL paper here.

The LogicalPlanner has a plan method that can generate one plan or sample multiple plans and aggregate them with num_samples.

Plan aggregation is available through LogicalPlans.aggregate(). Aggregated plans include a sample_plans attribute containing the candidate LogicalPlan objects used to produce the final plan.

Pruning

Pruning components are planned but not included yet.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

piglets-0.1.6.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

piglets-0.1.6-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file piglets-0.1.6.tar.gz.

File metadata

  • Download URL: piglets-0.1.6.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for piglets-0.1.6.tar.gz
Algorithm Hash digest
SHA256 e92c9a6a8e9fa8a83ffee081b5e935fe0a9c4da5b2aaa98cc4caf1230b9f0416
MD5 27927213feae9b3f87f76bec4eb9e419
BLAKE2b-256 89dc340a17995b77d9bb31ec6469f50721fad1d29f91a34ad288ef1fde20e9b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for piglets-0.1.6.tar.gz:

Publisher: publish.yml on mportdata/piglets

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file piglets-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: piglets-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for piglets-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 9bf6da48e86c2b778cf821af0d6a5d88a74e99717758e997dadd95966a57d795
MD5 79e7d1599f542fd2b1ae839ed126224a
BLAKE2b-256 bfc755984f96cfe941b192e7f17b8e54157a346f7aec6730546bc28fa7fdea13

See more details on using hashes here.

Provenance

The following attestation bundles were made for piglets-0.1.6-py3-none-any.whl:

Publisher: publish.yml on mportdata/piglets

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page