sqlparams


Namesqlparams JSON
Version 6.0.1 PyPI version JSON
download
home_page
SummaryConvert between various DB API 2.0 parameter styles.
upload_time2023-12-10 02:05:35
maintainer
docs_urlNone
author
requires_python>=3.8
licenseMIT License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            SQL Params
==========

*sqlparams* is a utility package for converting between various SQL
parameter styles. This can simplify the use of SQL parameters in queries by
allowing the use of named parameters where only ordinal are supported. Some
`Python DB API 2.0`_ compliant modules only support the ordinal *qmark* or
*format* style parameters (e.g., `pyodbc`_ only supports *qmark*). This
package provides a helper class, `SQLParams`_, that is used to convert
from any parameter style (*qmark*, *numeric*, *named*, *format*, *pyformat*;
and the non-standard *numeric_dollar* and *named_dollar*), and have them
safely converted to the desired parameter style.

.. _`Python DB API 2.0`: http://www.python.org/dev/peps/pep-0249/
.. _`pyodbc`: https://github.com/mkleehammer/pyodbc


Tutorial
--------

You first create an `SQLParams`_ instance specifying the named
parameter style you're converting from, and what ordinal style you're
converting to. Let's convert from *named* to *qmark* style::

  >>> import sqlparams
  >>> query = sqlparams.SQLParams('named', 'qmark')

Now, lets to convert a simple SQL SELECT query using the `SQLParams.format`_
method which accepts an SQL query, and a *dict* of parameters::

  >>> sql, params = query.format('SELECT * FROM users WHERE name = :name;', {'name': "Thorin"})

This returns the new SQL query using ordinal *qmark* parameters with the
corresponding list of ordinal parameters, which can be passed to the
`.execute()`_ method on a database cursor::

  >>> print sql
  SELECT * FROM users WHERE name = ?;
  >>> print params
  ['Thorin']

.. _`.execute()`: http://www.python.org/dev/peps/pep-0249/#id15

*tuple*\ s are also supported which allows for safe use of the SQL IN
operator::

  >>> sql, params = query.format("SELECT * FROM users WHERE name IN :names;", {'names': ("Dori", "Nori", "Ori")})
  >>> print sql
  SELECT * FROM users WHERE name in (?,?,?);
  >>> print params
  ['Dori', 'Nori', 'Ori']

You can also format multiple parameters for a single, shared query useful with
the `.executemany()`_ method of a database cursor::

  >>> sql, manyparams = query.formatmany("UPDATE users SET age = :age WHERE name = :name;", [{'name': "Dwalin", 'age': 169}, {'name': "Balin", 'age': 178}])
  >>> print sql
  UPDATE users SET age = ? WHERE name = ?;
  >>> print manyparams
  [[169, 'Dwalin'], [178, 'Balin']]

.. _`.executemany()`: http://www.python.org/dev/peps/pep-0249/#executemany

Please note that if an expanded *tuple* is used in `SQLParams.formatmany`_,
the tuple must be the same size in each of the parameter lists. Otherwise, you
might well use `SQLParams.format`_ in a for-loop.


Source
------

The source code for *sqlparams* is available from the GitHub repo
`cpburnz/python-sql-parameters`_.

.. _`cpburnz/python-sql-parameters`: https://github.com/cpburnz/python-sql-parameters.git


Installation
------------

*sqlparams* can be installed from source with::

  python setup.py install

*sqlparams* is also available for install through `PyPI`_::

  pip install sqlparams

.. _`PyPI`: http://pypi.python.org/pypi/sqlparams


Documentation
-------------

Documentation for *sqlparams* is available on `Read the Docs`_.

.. _`Read the Docs`: https://python-sql-parameters.readthedocs.org

.. _`SQLParams`: https://python-sql-parameters.readthedocs.io/en/latest/sqlparams.html#sqlparams.SQLParams
.. _`SQLParams.format`: https://python-sql-parameters.readthedocs.io/en/latest/sqlparams.html#sqlparams.SQLParams.format
.. _`SQLParams.formatmany`: https://python-sql-parameters.readthedocs.io/en/latest/sqlparams.html#sqlparams.SQLParams.formatmany



Change History
==============


6.0.1 (2023-12-09)
------------------

- Fix documentation.


6.0.0 (2023-12-09)
------------------

- Dropped support of EOL Python 3.7.
- Support Python 3.12.


5.1.0 (2023-03-14)
------------------

Improvements:

- Support `LiteralString`_.

.. _`LiteralString`: https://docs.python.org/3/library/typing.html#typing.LiteralString


5.0.0 (2022-08-11)
------------------

- Dropped support of EOL Python 3.6.
- Support Python 3.11.
- Changed build system to `pyproject.toml`_ and build backend to `setuptools.build_meta`_ which may have unforeseen consequences.
- Safely expand empty tuples. Fixes `Issue #8`_.
- Add support for stripping comments. This helps prevent expansion of unexpected variables in comments. Fixes `Issue #9`_.
- Rename GitHub project from `python-sql-parameters`_ to `python-sqlparams`_.

.. _`pyproject.toml`: https://pip.pypa.io/en/stable/reference/build-system/pyproject-toml/
.. _`setuptools.build_meta`: https://setuptools.pypa.io/en/latest/build_meta.html
.. _`Issue #8`: https://github.com/cpburnz/python-sqlparams/issues/8
.. _`Issue #9`: https://github.com/cpburnz/python-sqlparams/issues/9
.. _`python-sql-parameters`: https://github.com/cpburnz/python-sql-parameters
.. _`python-sqlparams`: https://github.com/cpburnz/python-sqlparams


4.0.0 (2022-06-06)
------------------

- Drop support for EOL Python 3.5.
-	`Issue #10`_: When converting to 'format'/'pyformat' types, escape existing '%' characters.
-	When converting from 'format'/'pyformat' types, set `escape_char=True` to unescape double '%' characters.

.. _`Issue #10`: https://github.com/cpburnz/python-sqlparams/issues/10



3.0.0 (2020-04-04)
------------------

- Major changes to internal implementation.
- Support converting any parameter style to any parameter style (all named,
  numeric, and ordinal styles).
- Renamed attribute `named` to `in_style` on `sqlparams.SQLParams`.
- Renamed attribute `ordinal` to `out_style` on `sqlparams.SQLParams`.
- Removed attributes `match` and `replace` from `sqlparams.SQLParams` which
  should have been private.
- Named parameters must now be valid identifiers (can no longer start with a
  digit to help prevent incorrectly matching common strings such as
  datetimes). Fixes `Issue #4`_.
- `Issue #7`_: Support dollar sign style for numeric and named parameters.

.. _`Issue #4`: https://github.com/cpburnz/python-sqlparams/issues/4
.. _`Issue #7`: https://github.com/cpburnz/python-sqlparams/issues/7


2.0.0 (2020-02-26)
------------------

- Drop support for EOL Python 2.7, 3.2, 3.3, 3.4.


1.2.0 (2020-02-26)
------------------

- Require setuptools.
- Support up to Python 3.8.


1.1.2 (2018-05-04)
------------------

- Improved support for byte strings.


1.1.1 (2017-09-07)
------------------

- Fixed support for byte strings.


1.1.0 (2017-08-30)
------------------

- Support Python 3.2+.


1.0.3 (2012-12-28)
------------------

- Fixed documentation for `issue 1`_.

.. _`issue 1`: https://github.com/cpburnz/python-sqlparams/issues/1


1.0.2 (2012-12-22)
------------------

- Added sphinx documentation.


1.0.1 (2012-12-20)
------------------

- Fixed running test as a script.


1.0.0 (2012-12-20)
------------------

- Initial release.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "sqlparams",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "\"Caleb P. Burns\" <cpburnz@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/d5/ed/7249310f429869dd1a28a475e8d11291eb1ba6ae108ad677d3ca27086573/sqlparams-6.0.1.tar.gz",
    "platform": null,
    "description": "SQL Params\n==========\n\n*sqlparams* is a utility package for converting between various SQL\nparameter styles. This can simplify the use of SQL parameters in queries by\nallowing the use of named parameters where only ordinal are supported. Some\n`Python DB API 2.0`_ compliant modules only support the ordinal *qmark* or\n*format* style parameters (e.g., `pyodbc`_ only supports *qmark*). This\npackage provides a helper class, `SQLParams`_, that is used to convert\nfrom any parameter style (*qmark*, *numeric*, *named*, *format*, *pyformat*;\nand the non-standard *numeric_dollar* and *named_dollar*), and have them\nsafely converted to the desired parameter style.\n\n.. _`Python DB API 2.0`: http://www.python.org/dev/peps/pep-0249/\n.. _`pyodbc`: https://github.com/mkleehammer/pyodbc\n\n\nTutorial\n--------\n\nYou first create an `SQLParams`_ instance specifying the named\nparameter style you're converting from, and what ordinal style you're\nconverting to. Let's convert from *named* to *qmark* style::\n\n  >>> import sqlparams\n  >>> query = sqlparams.SQLParams('named', 'qmark')\n\nNow, lets to convert a simple SQL SELECT query using the `SQLParams.format`_\nmethod which accepts an SQL query, and a *dict* of parameters::\n\n  >>> sql, params = query.format('SELECT * FROM users WHERE name = :name;', {'name': \"Thorin\"})\n\nThis returns the new SQL query using ordinal *qmark* parameters with the\ncorresponding list of ordinal parameters, which can be passed to the\n`.execute()`_ method on a database cursor::\n\n  >>> print sql\n  SELECT * FROM users WHERE name = ?;\n  >>> print params\n  ['Thorin']\n\n.. _`.execute()`: http://www.python.org/dev/peps/pep-0249/#id15\n\n*tuple*\\ s are also supported which allows for safe use of the SQL IN\noperator::\n\n  >>> sql, params = query.format(\"SELECT * FROM users WHERE name IN :names;\", {'names': (\"Dori\", \"Nori\", \"Ori\")})\n  >>> print sql\n  SELECT * FROM users WHERE name in (?,?,?);\n  >>> print params\n  ['Dori', 'Nori', 'Ori']\n\nYou can also format multiple parameters for a single, shared query useful with\nthe `.executemany()`_ method of a database cursor::\n\n  >>> sql, manyparams = query.formatmany(\"UPDATE users SET age = :age WHERE name = :name;\", [{'name': \"Dwalin\", 'age': 169}, {'name': \"Balin\", 'age': 178}])\n  >>> print sql\n  UPDATE users SET age = ? WHERE name = ?;\n  >>> print manyparams\n  [[169, 'Dwalin'], [178, 'Balin']]\n\n.. _`.executemany()`: http://www.python.org/dev/peps/pep-0249/#executemany\n\nPlease note that if an expanded *tuple* is used in `SQLParams.formatmany`_,\nthe tuple must be the same size in each of the parameter lists. Otherwise, you\nmight well use `SQLParams.format`_ in a for-loop.\n\n\nSource\n------\n\nThe source code for *sqlparams* is available from the GitHub repo\n`cpburnz/python-sql-parameters`_.\n\n.. _`cpburnz/python-sql-parameters`: https://github.com/cpburnz/python-sql-parameters.git\n\n\nInstallation\n------------\n\n*sqlparams* can be installed from source with::\n\n  python setup.py install\n\n*sqlparams* is also available for install through `PyPI`_::\n\n  pip install sqlparams\n\n.. _`PyPI`: http://pypi.python.org/pypi/sqlparams\n\n\nDocumentation\n-------------\n\nDocumentation for *sqlparams* is available on `Read the Docs`_.\n\n.. _`Read the Docs`: https://python-sql-parameters.readthedocs.org\n\n.. _`SQLParams`: https://python-sql-parameters.readthedocs.io/en/latest/sqlparams.html#sqlparams.SQLParams\n.. _`SQLParams.format`: https://python-sql-parameters.readthedocs.io/en/latest/sqlparams.html#sqlparams.SQLParams.format\n.. _`SQLParams.formatmany`: https://python-sql-parameters.readthedocs.io/en/latest/sqlparams.html#sqlparams.SQLParams.formatmany\n\n\n\nChange History\n==============\n\n\n6.0.1 (2023-12-09)\n------------------\n\n- Fix documentation.\n\n\n6.0.0 (2023-12-09)\n------------------\n\n- Dropped support of EOL Python 3.7.\n- Support Python 3.12.\n\n\n5.1.0 (2023-03-14)\n------------------\n\nImprovements:\n\n- Support `LiteralString`_.\n\n.. _`LiteralString`: https://docs.python.org/3/library/typing.html#typing.LiteralString\n\n\n5.0.0 (2022-08-11)\n------------------\n\n- Dropped support of EOL Python 3.6.\n- Support Python 3.11.\n- Changed build system to `pyproject.toml`_ and build backend to `setuptools.build_meta`_ which may have unforeseen consequences.\n- Safely expand empty tuples. Fixes `Issue #8`_.\n- Add support for stripping comments. This helps prevent expansion of unexpected variables in comments. Fixes `Issue #9`_.\n- Rename GitHub project from `python-sql-parameters`_ to `python-sqlparams`_.\n\n.. _`pyproject.toml`: https://pip.pypa.io/en/stable/reference/build-system/pyproject-toml/\n.. _`setuptools.build_meta`: https://setuptools.pypa.io/en/latest/build_meta.html\n.. _`Issue #8`: https://github.com/cpburnz/python-sqlparams/issues/8\n.. _`Issue #9`: https://github.com/cpburnz/python-sqlparams/issues/9\n.. _`python-sql-parameters`: https://github.com/cpburnz/python-sql-parameters\n.. _`python-sqlparams`: https://github.com/cpburnz/python-sqlparams\n\n\n4.0.0 (2022-06-06)\n------------------\n\n- Drop support for EOL Python 3.5.\n-\t`Issue #10`_: When converting to 'format'/'pyformat' types, escape existing '%' characters.\n-\tWhen converting from 'format'/'pyformat' types, set `escape_char=True` to unescape double '%' characters.\n\n.. _`Issue #10`: https://github.com/cpburnz/python-sqlparams/issues/10\n\n\n\n3.0.0 (2020-04-04)\n------------------\n\n- Major changes to internal implementation.\n- Support converting any parameter style to any parameter style (all named,\n  numeric, and ordinal styles).\n- Renamed attribute `named` to `in_style` on `sqlparams.SQLParams`.\n- Renamed attribute `ordinal` to `out_style` on `sqlparams.SQLParams`.\n- Removed attributes `match` and `replace` from `sqlparams.SQLParams` which\n  should have been private.\n- Named parameters must now be valid identifiers (can no longer start with a\n  digit to help prevent incorrectly matching common strings such as\n  datetimes). Fixes `Issue #4`_.\n- `Issue #7`_: Support dollar sign style for numeric and named parameters.\n\n.. _`Issue #4`: https://github.com/cpburnz/python-sqlparams/issues/4\n.. _`Issue #7`: https://github.com/cpburnz/python-sqlparams/issues/7\n\n\n2.0.0 (2020-02-26)\n------------------\n\n- Drop support for EOL Python 2.7, 3.2, 3.3, 3.4.\n\n\n1.2.0 (2020-02-26)\n------------------\n\n- Require setuptools.\n- Support up to Python 3.8.\n\n\n1.1.2 (2018-05-04)\n------------------\n\n- Improved support for byte strings.\n\n\n1.1.1 (2017-09-07)\n------------------\n\n- Fixed support for byte strings.\n\n\n1.1.0 (2017-08-30)\n------------------\n\n- Support Python 3.2+.\n\n\n1.0.3 (2012-12-28)\n------------------\n\n- Fixed documentation for `issue 1`_.\n\n.. _`issue 1`: https://github.com/cpburnz/python-sqlparams/issues/1\n\n\n1.0.2 (2012-12-22)\n------------------\n\n- Added sphinx documentation.\n\n\n1.0.1 (2012-12-20)\n------------------\n\n- Fixed running test as a script.\n\n\n1.0.0 (2012-12-20)\n------------------\n\n- Initial release.\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Convert between various DB API 2.0 parameter styles.",
    "version": "6.0.1",
    "project_urls": {
        "Documentation": "https://python-sql-parameters.readthedocs.io/en/latest/index.html",
        "Issue Tracker": "https://github.com/cpburnz/python-sqlparams/issues",
        "Source Code": "https://github.com/cpburnz/python-sqlparams"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "836d61f7d6affb67e676a8b2386d15f109f0b368d7074d9cb6bbd63df4215123",
                "md5": "e1af2d80fd74a672904f126c1ca7b8eb",
                "sha256": "566651376315c832876be4a0f58ffa23a23fab257d77ee492bdf8d301e169d0d"
            },
            "downloads": -1,
            "filename": "sqlparams-6.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e1af2d80fd74a672904f126c1ca7b8eb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 16759,
            "upload_time": "2023-12-10T02:05:33",
            "upload_time_iso_8601": "2023-12-10T02:05:33.813872Z",
            "url": "https://files.pythonhosted.org/packages/83/6d/61f7d6affb67e676a8b2386d15f109f0b368d7074d9cb6bbd63df4215123/sqlparams-6.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d5ed7249310f429869dd1a28a475e8d11291eb1ba6ae108ad677d3ca27086573",
                "md5": "66ce48baf6f9f9489498758ac0865b72",
                "sha256": "032b2f949d4afbcbfa24003f6fb407f2fc8468184e3d8ca3d59ba6b30d4935bf"
            },
            "downloads": -1,
            "filename": "sqlparams-6.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "66ce48baf6f9f9489498758ac0865b72",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 32290,
            "upload_time": "2023-12-10T02:05:35",
            "upload_time_iso_8601": "2023-12-10T02:05:35.589754Z",
            "url": "https://files.pythonhosted.org/packages/d5/ed/7249310f429869dd1a28a475e8d11291eb1ba6ae108ad677d3ca27086573/sqlparams-6.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-10 02:05:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cpburnz",
    "github_project": "python-sqlparams",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "sqlparams"
}
        
Elapsed time: 0.14806s