TextualOrm
This tool generates SQL queries from natural language and retrieves query results. This orm generates sql queries from your input and the specifics of your connected database and can also run them to retrieve records.
Find the code here
Currently, this ORM only supports retrieval queries. Queries that perform delete, create, or other CRUD (Create, Read, Update, Delete) actions will not be executed on your database..
The core of this application is the use of Large Language Models to generate the sql queries. This orm currently supports two LLMs:
- SQL Generator LLM - (free and the default llm used).
- OpenAI (requires subscription to OpenAI)
You can find more information about the default SQL Generator LLM by going to the link here. This has been fine-trained from the flan-t5-base model.
Requirements
- Python
- Postgres
- Redis Note: Support for additional databases such as MySQL will be added in future updates.
Installation
pip install textual_orm
Usage Instructions
-
Initialize the Orm
from textual_orm import TextualOrm textual_orm = TextualOrm(connection_string="postgresql://user:password@host:port/db_name", llm_type=LLMType.DEFAULT, redis_host="localhost", redis_port=6379)To use the OpenAI implementation, add your api-key to the arguments:
from textual_orm import TextualOrm textual_orm = TextualOrm(connection_string="postgresql://user:password@host:port/db_name", llm_type=LLMType.DEFAULT, redis_host="localhost", redis_port=6379, api-key="") -
Call the setup method:
await textual_orm.setup() -
Generate the SQL query
sql_query = await textual_orm.make_sql_request("List of settings", ["setting"]) print(sql_query)This method takes three arguments:
- question: Input question
- tables: List of tables as reference
- request_data: A boolean to indicate if it should query the database or return only the sql_query (default value is False)
By default, the make_sql_request does not actually query the database. It returns back the generated sql query which you can look at and verify. To get an alternative sql query, please modify your input question.To query the database with the generated sql query. Call the method passing in
request_data=True. This will return a response in this format:{ 'query': 'SELECT * FROM setting ORDER BY created_at DESC LIMIT 5;', 'data': [<records>] }Where data is a list of records from the query response.
datawill be None ifrequest_data=Falseas in the default case.
Note that first time run may take a little time.
For better performance, speed and caching, redis is required.
Additional Arguments
This orm uses a default postgres max pool of 10. You can modify it if needed by passing your value to the max_pool argument.
Below is a list of other supported arguments to Orm:
min_size=1minimum size of poolmax_size=10maxiumum size of poolapi_key=""api key for the given llm
Metadata
Release files for textual-orm 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| textual_orm-0.1.3.tar.gz | 10.0 kB | Without provenance | Details for textual_orm-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| textual_orm-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for textual_orm-0.1.3-py3-none-any.whl |
Total release size: 21.9 kB
Release files / textual_orm-0.1.3.tar.gz
| Download URL | textual_orm-0.1.3.tar.gz |
|---|---|
| Size | 10.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7464a75ad9f2bf2a9e640ae2d6301f0f0d9bc65659e77381c65339c4edc678f4
|
|
BLAKE2b-256 checksum How to use checksums |
b40627b65a97d6cf965ee17113730d3b98c5825df49ad328971d4a3c01c0be9c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Release files / textual_orm-0.1.3-py3-none-any.whl
| Download URL | textual_orm-0.1.3-py3-none-any.whl |
|---|---|
| Size | 11.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
25bb11ed18bfa90f1d452581d9761efe6ef514c7248d84262d8d522422d999fe
|
|
BLAKE2b-256 checksum How to use checksums |
77d19dd5a0ea61971f7b7b1c57a112792001d1c74469b72be2b30a4d50fddaf5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Security for textual-orm 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.