Skip to main content

A flask blueprint providing a read-lny API for querying RDBMS

Project description

apisql

PyPI - Python Version

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 exceed num_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 or xlsx. Defaults to csv.

  • 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 strings
    • yesno, 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


Download files

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

Source Distribution

apisql-0.3.5.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

apisql-0.3.5-py2.py3-none-any.whl (19.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file apisql-0.3.5.tar.gz.

File metadata

  • Download URL: apisql-0.3.5.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.5

File hashes

Hashes for apisql-0.3.5.tar.gz
Algorithm Hash digest
SHA256 df2068edd7d89fc1fe9a7ed7260775be6bd0a762dae6bbdb1bb1a58ec6c9e21f
MD5 b09faff2de862fe9725d77b848503c3f
BLAKE2b-256 bc14d8a8e714c70155931f972b23db795b7b644a85302ff216b36f4babe4b890

See more details on using hashes here.

Provenance

File details

Details for the file apisql-0.3.5-py2.py3-none-any.whl.

File metadata

  • Download URL: apisql-0.3.5-py2.py3-none-any.whl
  • Upload date:
  • Size: 19.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.5

File hashes

Hashes for apisql-0.3.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 823561df8ce92d11393d66ba314105afead2f7f48e99ea11b318f70b9b4d7eae
MD5 4fddb6b4e1d2e322e0d1cd0fa5076159
BLAKE2b-256 34c27ee0196cf94f96f9466f9fd472d59a8016ed5e2b5a81fd93af15383fe647

See more details on using hashes here.

Provenance

Supported by

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