apisql


Nameapisql JSON
Version 0.6.1 PyPI version JSON
download
home_pagehttps://github.com/dataspot/apisql
SummaryA flask blueprint providing a read-lny API for querying RDBMS
upload_time2024-06-27 08:29:27
maintainerNone
docs_urlNone
authorAdam Kariv
requires_pythonNone
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": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "data",
    "author": "Adam Kariv",
    "author_email": "adam.kariv@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/cf/47/9a1e504922131368c40d1073fdc18252a5f6c24344988c1617091fcf8913/apisql-0.6.1.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.6.1",
    "project_urls": {
        "Homepage": "https://github.com/dataspot/apisql"
    },
    "split_keywords": [
        "data"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "94499288be6079b6b8076680fc2a20a26c08ec83f4f023f12b8bf502f8968788",
                "md5": "159bf41d969b42852f46cb7c7392d50f",
                "sha256": "eb1adf26df0b6e6a03b6e739fafa0b35cef67a7069d2a52b1c0ff5404fde59f3"
            },
            "downloads": -1,
            "filename": "apisql-0.6.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "159bf41d969b42852f46cb7c7392d50f",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 20119,
            "upload_time": "2024-06-27T08:29:25",
            "upload_time_iso_8601": "2024-06-27T08:29:25.720917Z",
            "url": "https://files.pythonhosted.org/packages/94/49/9288be6079b6b8076680fc2a20a26c08ec83f4f023f12b8bf502f8968788/apisql-0.6.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cf479a1e504922131368c40d1073fdc18252a5f6c24344988c1617091fcf8913",
                "md5": "52cbc0ba1a4e7c071c98f840605f07e4",
                "sha256": "814f8eb129b1fe1b68647e74f1abe247409443afc1639c9af1abf7c526d3cd05"
            },
            "downloads": -1,
            "filename": "apisql-0.6.1.tar.gz",
            "has_sig": false,
            "md5_digest": "52cbc0ba1a4e7c071c98f840605f07e4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10953,
            "upload_time": "2024-06-27T08:29:27",
            "upload_time_iso_8601": "2024-06-27T08:29:27.765087Z",
            "url": "https://files.pythonhosted.org/packages/cf/47/9a1e504922131368c40d1073fdc18252a5f6c24344988c1617091fcf8913/apisql-0.6.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-27 08:29:27",
    "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.33711s