apisql


Nameapisql JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://github.com/dataspot/apisql
SummaryA flask blueprint providing a read-lny API for querying RDBMS
upload_time2023-11-12 21:35:32
maintainer
docs_urlNone
authorAdam Kariv
requires_python
licenseMIT
keywords data
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # apisql

![PyPI - Python Version](https://img.shields.io/pypi/pyversions/apisql.svg)

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:


```python

    from apisql import apisql_blueprint

    app.register_blueprint(
        apisql_blueprint(connection_string='psql://host/database', max_rows=1000, debug=False),
        url_prefix='/api/db/'
    )
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dataspot/apisql",
    "name": "apisql",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "data",
    "author": "Adam Kariv",
    "author_email": "adam.kariv@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/da/fe/9303a3d89f41c8de4563f0ec87a5038dbc6a6f3139950ae7f8838dff51dd/apisql-0.4.0.tar.gz",
    "platform": null,
    "description": "# apisql\n\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/apisql.svg)\n\napisql is a flask blueprint providing an API for read-only access for a DBMS using direct SQL Queries\n\n## endpoints\n\n### `/query`\n\nReturns query results in json format.\n\nQuery parameters that can be send:\n- **query**: The SQL query to execute on the DB. The query can be provided in plain text or base64 encoded.\n- **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.\n- **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`.\n- **page**: Which page to fetch, starting from page 0\n\n### `/download`\n\nDownloads query results in either csv, xls or xlsx format.\n\nQuery parameters that can be send:\n- **query**: The SQL query to execute on the DB. The query can be provided in plain text or base64 encoded.\n- **format**: Either `csv` or `xlsx`. Defaults to `csv`.\n- **filename**: The filename for the file to be downloaded, *without the extension*. Defaults to `query-results`.\n- **headers**: A semicolon separated list of the headers for the output file. Headers should match the field names that appear in the query.\n  Headers may contain one or more modifiers, which appear after a colon. The currently supported modifiers are:\n  - `number`, to convert numeric values to strings\n  - `yesno`, which converts boolean values to \"Yes\" / \"No\"\n  - `comma-separated`, which converts arrays of strings to a comma separated list of these strings.\n  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.\n\n  Example:\n  `Fiscal Year:number<fiscal_year;Leap Year:yesno<0;`\n\n\n\n**Example:**\nFor the following SQL:\n```\nselect employee_name as \"Employee Name\", employee_salary as \"Salary\", is_manager as \"Managerial role?\" from employees\n```\n\n`headers` could be specified as `Employee Name;Managerial role?:yesno;Salary:number`.\n\n## configuration\n\nFlask configuration for this blueprint:\n\n\n```python\n\n    from apisql import apisql_blueprint\n\n    app.register_blueprint(\n        apisql_blueprint(connection_string='psql://host/database', max_rows=1000, debug=False),\n        url_prefix='/api/db/'\n    )\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A flask blueprint providing a read-lny API for querying RDBMS",
    "version": "0.4.0",
    "project_urls": {
        "Homepage": "https://github.com/dataspot/apisql"
    },
    "split_keywords": [
        "data"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7ae5ef996490ed64a09a290caf8ba0768dba8fa0dd330c487fb1d40c45937c4a",
                "md5": "41a60d4937b377e6865cba6547e5478f",
                "sha256": "0d76a7bc32aa08ddd1938929ae99a9305f191c60118147bba469f40199c19b04"
            },
            "downloads": -1,
            "filename": "apisql-0.4.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "41a60d4937b377e6865cba6547e5478f",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 19777,
            "upload_time": "2023-11-12T21:35:30",
            "upload_time_iso_8601": "2023-11-12T21:35:30.488077Z",
            "url": "https://files.pythonhosted.org/packages/7a/e5/ef996490ed64a09a290caf8ba0768dba8fa0dd330c487fb1d40c45937c4a/apisql-0.4.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dafe9303a3d89f41c8de4563f0ec87a5038dbc6a6f3139950ae7f8838dff51dd",
                "md5": "2fd61f87d2912f41110eba38ab3d698e",
                "sha256": "61fb2a579f2bc00b77264866fc256af85f480cc4b4e6e1906d084b491f9320a2"
            },
            "downloads": -1,
            "filename": "apisql-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "2fd61f87d2912f41110eba38ab3d698e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10551,
            "upload_time": "2023-11-12T21:35:32",
            "upload_time_iso_8601": "2023-11-12T21:35:32.152708Z",
            "url": "https://files.pythonhosted.org/packages/da/fe/9303a3d89f41c8de4563f0ec87a5038dbc6a6f3139950ae7f8838dff51dd/apisql-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-12 21:35:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dataspot",
    "github_project": "apisql",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "apisql"
}
        
Elapsed time: 0.13828s