A flask blueprint providing a read-lny API for querying RDBMS
Project description
apisql
apisql is a flask blueprint providing an API for read-only access for a DBMS using direct SQL Queries
endpoints
/query
Returns query results in json format.
Query parameters that can be send:
- query: The SQL query to execute on the DB. The query can be provided in plain text or base64 encoded.
- num_rows: The maximum number of rows to return. If not specified, will return the aount defined in the configuration, the amount defined in the environment variable
APISQL__MAX_ROWS
or 100. - page_size: The size of the 'page', when doing paging. By default will use
num_rows
and in any way the page size it won't exceednum_rows
. - page: Which page to fetch, starting from page 0
/download
Downloads query results in either csv, xls or xlsx format.
Query parameters that can be send:
-
query: The SQL query to execute on the DB. The query can be provided in plain text or base64 encoded.
-
format: Either
csv
orxlsx
. Defaults tocsv
. -
filename: The filename for the file to be downloaded, without the extension. Defaults to
query-results
. -
headers: A semicolon separated list of the headers for the output file. Headers should match the field names that appear in the query. Headers may contain one or more modifiers, which appear after a colon. The currently supported modifiers are:
number
, to convert numeric values to stringsyesno
, which converts boolean values to "Yes" / "No"comma-separated
, which converts arrays of strings to a comma separated list of these strings. Finally, the content for a column may be fetched from a different field in the query output, by specifying the field name after a<
character.
Example:
Fiscal Year:number<fiscal_year;Leap Year:yesno<0;
Example: For the following SQL:
select employee_name as "Employee Name", employee_salary as "Salary", is_manager as "Managerial role?" from employees
headers
could be specified as Employee Name;Managerial role?:yesno;Salary:number
.
configuration
Flask configuration for this blueprint:
from apisql import apisql_blueprint
app.register_blueprint(
apisql_blueprint(connection_string='psql://host/database', max_rows=1000, debug=False),
url_prefix='/api/db/'
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file apisql-0.6.1.tar.gz
.
File metadata
- Download URL: apisql-0.6.1.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 814f8eb129b1fe1b68647e74f1abe247409443afc1639c9af1abf7c526d3cd05 |
|
MD5 | 52cbc0ba1a4e7c071c98f840605f07e4 |
|
BLAKE2b-256 | cf479a1e504922131368c40d1073fdc18252a5f6c24344988c1617091fcf8913 |
File details
Details for the file apisql-0.6.1-py2.py3-none-any.whl
.
File metadata
- Download URL: apisql-0.6.1-py2.py3-none-any.whl
- Upload date:
- Size: 20.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb1adf26df0b6e6a03b6e739fafa0b35cef67a7069d2a52b1c0ff5404fde59f3 |
|
MD5 | 159bf41d969b42852f46cb7c7392d50f |
|
BLAKE2b-256 | 94499288be6079b6b8076680fc2a20a26c08ec83f4f023f12b8bf502f8968788 |