databasez


Namedatabasez JSON
Version 0.7.2 PyPI version JSON
download
home_page
SummaryAsync database support for Python.
upload_time2024-01-24 18:53:21
maintainer
docs_urlNone
author
requires_python>=3.8
license
keywords asyncio esmerald mysql postgres saffier sqlalchemy sqlite
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Databasez

<p align="center">
  <a href="https://databasez.tarsild.io"><img src="https://res.cloudinary.com/dymmond/image/upload/v1680611626/databasez/logo-cmp_luizb0.png" alt='databasez'></a>
</p>

<p align="center">
    <em>🚀 Async database support for Python. 🚀</em>
</p>

<p align="center">
<a href="https://github.com/tarsil/databasez/workflows/Test%20Suite/badge.svg?event=push&branch=main" target="_blank">
    <img src="https://github.com/tarsil/databasez/workflows/Test%20Suite/badge.svg?event=push&branch=main" alt="Test Suite">
</a>

<a href="https://pypi.org/project/databasez" target="_blank">
    <img src="https://img.shields.io/pypi/v/databasez?color=%2334D058&label=pypi%20package" alt="Package version">
</a>

<a href="https://pypi.org/project/databasez" target="_blank">
    <img src="https://img.shields.io/pypi/pyversions/databasez.svg?color=%2334D058" alt="Supported Python versions">
</a>
</p>

---

**Documentation**: [https://databasez.tarsild.io](https://databasez.tarsild.io) 📚

**Source Code**: [https://github.com/tarsil/databasez](https://github.com/tarsil/databasez)

---

## Motivation

There is a great package from [Encode](https://github.com/encode/databases/) that was doing what
this package was initially forked to do but Encode is also very busy with other projects and
without the proper time to maintain the so much required package.

From a need to extend to new drivers and newest technologies and adding extra features common and
useful to the many, [Databases](https://github.com/encode/databases/) was forked to become
**Databasez**.

This package is 100% backwards compatible with [Databases](https://github.com/encode/databases/)
from Encode and will remain like this for the time being but adding extra features and regular
updates as well as continuing to be community driven.

By the time this project was created, Databases was yet to merge possible SQLAlchemy 2.0 changes
from the author of this package and therefore, this package aims to unblock
a lot of the projects out there that want SQLAlchemy 2.0 with the best of databases with new features.

A lot of packages depends of Databases and this was the main reason for the fork of **Databasez**.

It allows you to make queries using the powerful [SQLAlchemy Core][sqlalchemy-core]
expression language, and provides support for PostgreSQL, MySQL, SQLite and MSSQL.

Databasez is suitable for integrating against any async Web framework, such as [Esmerald][esmerald],
[Starlette][starlette], [Sanic][sanic], [Responder][responder], [Quart][quart], [aiohttp][aiohttp],
[Tornado][tornado], or [FastAPI][fastapi].

Databasez was built for Python 3.8+ and on the top of the newest **SQLAlchemy 2** and gives you
simple asyncio support for a range of databases.

### Special notes

This package couldn't exist without [Databases](https://www.encode.io/databasex/) and the continuous work
done by the amazing team behind it. For that reason, thank you!

## Installation

```shell
$ pip install databasez
```

If you are interested in using the [test client](./test-client.md), you can also install:

```shell
$ pip install databasez[testing]
```

## What does databasez support at the moment

Databasez currently supports `sqlite`, `postgres`, `mysql` and `sql server`. More drivers can and
will be added in the future.

Database drivers supported are:

* [asyncpg][asyncpg] - For postgres.
* [aiopg][aiopg] - For postgres.
* [aiomysql][aiomysql] - For MySQL/MariaDB.
* [asyncmy][asyncmy] - For MySQL/MariaDB.
* [aiosqlite][aiosqlite] - For SQLite.
* [aioodbc][aioodbc] - For MSSQL (SQL Server).

### Driver installation

You can install the required database drivers with:

#### Postgres

```shell
$ pip install databasez[asyncpg]
```

or

```shell
$ pip install databasez[aiopg]
```

#### MySQL/MariaDB

```shell
$ pip install databasez[aiomysql]
```

or

```shell
$ pip install databasez[asyncmy]
```

#### SQLite

```shell
$ pip install databasez[aiosqlite]
```

#### MSSQL

```shell
$ pip install databasez[aioodbc]
```

!!! Note
    Note that if you are using any synchronous SQLAlchemy functions such as `engine.create_all()`
    or [alembic][alembic] migrations then you still have to install a synchronous DB driver:
    [psycopg2][psycopg2] for PostgreSQL, [pymysql][pymysql] for MySQL and
    [pyodbc][pyodbc] for SQL Server.

---

## Quickstart

For a simple quickstart example, we will be creating a simple SQLite database to run some queries
against.

First, install the required drivers for `SQLite` and `ipython`. The `ipython` is to have an
interactive python shell with some extras. IPython also supports `await`, which is exactly
what we need. [See more details](https://ipython.org/) about it.

**Install the required drivers**

```shell
$ pip install databasez[aiosqlite]
$ pip install ipython
```

Now from the console, we can run a simple example.


```python
# Create a database instance, and connect to it.
from databasez import Database

database = Database("sqlite+aiosqlite:///example.db")
await database.connect()

# Create a table.
query = """CREATE TABLE HighScores (id INTEGER PRIMARY KEY, name VARCHAR(100), score INTEGER)"""
await database.execute(query=query)

# Insert some data.
query = "INSERT INTO HighScores(name, score) VALUES (:name, :score)"
values = [
    {"name": "Daisy", "score": 92},
    {"name": "Neil", "score": 87},
    {"name": "Carol", "score": 43},
]
await database.execute_many(query=query, values=values)

# Run a database query.
query = "SELECT * FROM HighScores"
rows = await database.fetch_all(query=query)

print("High Scores:", rows)
```

Check out the documentation on [making database queries](https://databasez.tarsild.io/queries/)
for examples of how to start using databasez together with SQLAlchemy core expressions.


[sqlalchemy-core]: https://docs.sqlalchemy.org/en/latest/core/
[sqlalchemy-core-tutorial]: https://docs.sqlalchemy.org/en/latest/core/tutorial.html
[alembic]: https://alembic.sqlalchemy.org/en/latest/
[psycopg2]: https://www.psycopg.org/
[pymysql]: https://github.com/PyMySQL/PyMySQL
[pyodbc]: https://github.com/mkleehammer/pyodbc
[asyncpg]: https://github.com/MagicStack/asyncpg
[aiopg]: https://github.com/aio-libs/aiopg
[aiomysql]: https://github.com/aio-libs/aiomysql
[asyncmy]: https://github.com/long2ice/asyncmy
[aiosqlite]: https://github.com/omnilib/aiosqlite
[aioodbc]: https://aioodbc.readthedocs.io/en/latest/

[esmerald]: https://github.com/dymmond/esmerald
[starlette]: https://github.com/encode/starlette
[sanic]: https://github.com/huge-success/sanic
[responder]: https://github.com/kennethreitz/responder
[quart]: https://gitlab.com/pgjones/quart
[aiohttp]: https://github.com/aio-libs/aiohttp
[tornado]: https://github.com/tornadoweb/tornado
[fastapi]: https://github.com/tiangolo/fastapi

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "databasez",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "asyncio,esmerald,mysql,postgres,saffier,sqlalchemy,sqlite",
    "author": "",
    "author_email": "Tiago Silva <tiago.arasilva@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/bd/48/06b7040acd7b7b43ae66054a54ae0fd10d2bcda5a0a533a3fab6f85ba8cb/databasez-0.7.2.tar.gz",
    "platform": null,
    "description": "# Databasez\n\n<p align=\"center\">\n  <a href=\"https://databasez.tarsild.io\"><img src=\"https://res.cloudinary.com/dymmond/image/upload/v1680611626/databasez/logo-cmp_luizb0.png\" alt='databasez'></a>\n</p>\n\n<p align=\"center\">\n    <em>\ud83d\ude80 Async database support for Python. \ud83d\ude80</em>\n</p>\n\n<p align=\"center\">\n<a href=\"https://github.com/tarsil/databasez/workflows/Test%20Suite/badge.svg?event=push&branch=main\" target=\"_blank\">\n    <img src=\"https://github.com/tarsil/databasez/workflows/Test%20Suite/badge.svg?event=push&branch=main\" alt=\"Test Suite\">\n</a>\n\n<a href=\"https://pypi.org/project/databasez\" target=\"_blank\">\n    <img src=\"https://img.shields.io/pypi/v/databasez?color=%2334D058&label=pypi%20package\" alt=\"Package version\">\n</a>\n\n<a href=\"https://pypi.org/project/databasez\" target=\"_blank\">\n    <img src=\"https://img.shields.io/pypi/pyversions/databasez.svg?color=%2334D058\" alt=\"Supported Python versions\">\n</a>\n</p>\n\n---\n\n**Documentation**: [https://databasez.tarsild.io](https://databasez.tarsild.io) \ud83d\udcda\n\n**Source Code**: [https://github.com/tarsil/databasez](https://github.com/tarsil/databasez)\n\n---\n\n## Motivation\n\nThere is a great package from [Encode](https://github.com/encode/databases/) that was doing what\nthis package was initially forked to do but Encode is also very busy with other projects and\nwithout the proper time to maintain the so much required package.\n\nFrom a need to extend to new drivers and newest technologies and adding extra features common and\nuseful to the many, [Databases](https://github.com/encode/databases/) was forked to become\n**Databasez**.\n\nThis package is 100% backwards compatible with [Databases](https://github.com/encode/databases/)\nfrom Encode and will remain like this for the time being but adding extra features and regular\nupdates as well as continuing to be community driven.\n\nBy the time this project was created, Databases was yet to merge possible SQLAlchemy 2.0 changes\nfrom the author of this package and therefore, this package aims to unblock\na lot of the projects out there that want SQLAlchemy 2.0 with the best of databases with new features.\n\nA lot of packages depends of Databases and this was the main reason for the fork of **Databasez**.\n\nIt allows you to make queries using the powerful [SQLAlchemy Core][sqlalchemy-core]\nexpression language, and provides support for PostgreSQL, MySQL, SQLite and MSSQL.\n\nDatabasez is suitable for integrating against any async Web framework, such as [Esmerald][esmerald],\n[Starlette][starlette], [Sanic][sanic], [Responder][responder], [Quart][quart], [aiohttp][aiohttp],\n[Tornado][tornado], or [FastAPI][fastapi].\n\nDatabasez was built for Python 3.8+ and on the top of the newest **SQLAlchemy 2** and gives you\nsimple asyncio support for a range of databases.\n\n### Special notes\n\nThis package couldn't exist without [Databases](https://www.encode.io/databasex/) and the continuous work\ndone by the amazing team behind it. For that reason, thank you!\n\n## Installation\n\n```shell\n$ pip install databasez\n```\n\nIf you are interested in using the [test client](./test-client.md), you can also install:\n\n```shell\n$ pip install databasez[testing]\n```\n\n## What does databasez support at the moment\n\nDatabasez currently supports `sqlite`, `postgres`, `mysql` and `sql server`. More drivers can and\nwill be added in the future.\n\nDatabase drivers supported are:\n\n* [asyncpg][asyncpg] - For postgres.\n* [aiopg][aiopg] - For postgres.\n* [aiomysql][aiomysql] - For MySQL/MariaDB.\n* [asyncmy][asyncmy] - For MySQL/MariaDB.\n* [aiosqlite][aiosqlite] - For SQLite.\n* [aioodbc][aioodbc] - For MSSQL (SQL Server).\n\n### Driver installation\n\nYou can install the required database drivers with:\n\n#### Postgres\n\n```shell\n$ pip install databasez[asyncpg]\n```\n\nor\n\n```shell\n$ pip install databasez[aiopg]\n```\n\n#### MySQL/MariaDB\n\n```shell\n$ pip install databasez[aiomysql]\n```\n\nor\n\n```shell\n$ pip install databasez[asyncmy]\n```\n\n#### SQLite\n\n```shell\n$ pip install databasez[aiosqlite]\n```\n\n#### MSSQL\n\n```shell\n$ pip install databasez[aioodbc]\n```\n\n!!! Note\n    Note that if you are using any synchronous SQLAlchemy functions such as `engine.create_all()`\n    or [alembic][alembic] migrations then you still have to install a synchronous DB driver:\n    [psycopg2][psycopg2] for PostgreSQL, [pymysql][pymysql] for MySQL and\n    [pyodbc][pyodbc] for SQL Server.\n\n---\n\n## Quickstart\n\nFor a simple quickstart example, we will be creating a simple SQLite database to run some queries\nagainst.\n\nFirst, install the required drivers for `SQLite` and `ipython`. The `ipython` is to have an\ninteractive python shell with some extras. IPython also supports `await`, which is exactly\nwhat we need. [See more details](https://ipython.org/) about it.\n\n**Install the required drivers**\n\n```shell\n$ pip install databasez[aiosqlite]\n$ pip install ipython\n```\n\nNow from the console, we can run a simple example.\n\n\n```python\n# Create a database instance, and connect to it.\nfrom databasez import Database\n\ndatabase = Database(\"sqlite+aiosqlite:///example.db\")\nawait database.connect()\n\n# Create a table.\nquery = \"\"\"CREATE TABLE HighScores (id INTEGER PRIMARY KEY, name VARCHAR(100), score INTEGER)\"\"\"\nawait database.execute(query=query)\n\n# Insert some data.\nquery = \"INSERT INTO HighScores(name, score) VALUES (:name, :score)\"\nvalues = [\n    {\"name\": \"Daisy\", \"score\": 92},\n    {\"name\": \"Neil\", \"score\": 87},\n    {\"name\": \"Carol\", \"score\": 43},\n]\nawait database.execute_many(query=query, values=values)\n\n# Run a database query.\nquery = \"SELECT * FROM HighScores\"\nrows = await database.fetch_all(query=query)\n\nprint(\"High Scores:\", rows)\n```\n\nCheck out the documentation on [making database queries](https://databasez.tarsild.io/queries/)\nfor examples of how to start using databasez together with SQLAlchemy core expressions.\n\n\n[sqlalchemy-core]: https://docs.sqlalchemy.org/en/latest/core/\n[sqlalchemy-core-tutorial]: https://docs.sqlalchemy.org/en/latest/core/tutorial.html\n[alembic]: https://alembic.sqlalchemy.org/en/latest/\n[psycopg2]: https://www.psycopg.org/\n[pymysql]: https://github.com/PyMySQL/PyMySQL\n[pyodbc]: https://github.com/mkleehammer/pyodbc\n[asyncpg]: https://github.com/MagicStack/asyncpg\n[aiopg]: https://github.com/aio-libs/aiopg\n[aiomysql]: https://github.com/aio-libs/aiomysql\n[asyncmy]: https://github.com/long2ice/asyncmy\n[aiosqlite]: https://github.com/omnilib/aiosqlite\n[aioodbc]: https://aioodbc.readthedocs.io/en/latest/\n\n[esmerald]: https://github.com/dymmond/esmerald\n[starlette]: https://github.com/encode/starlette\n[sanic]: https://github.com/huge-success/sanic\n[responder]: https://github.com/kennethreitz/responder\n[quart]: https://gitlab.com/pgjones/quart\n[aiohttp]: https://github.com/aio-libs/aiohttp\n[tornado]: https://github.com/tornadoweb/tornado\n[fastapi]: https://github.com/tiangolo/fastapi\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Async database support for Python.",
    "version": "0.7.2",
    "project_urls": {
        "Changelog": "https://databasez.tarsild.io/release-notes/",
        "Documentation": "https://databasez.tarsild/",
        "Funding": "https://github.com/sponsors/tarsil",
        "Homepage": "https://github.com/tarsil/databasez",
        "Source": "https://github.com/tarsil/databasez"
    },
    "split_keywords": [
        "asyncio",
        "esmerald",
        "mysql",
        "postgres",
        "saffier",
        "sqlalchemy",
        "sqlite"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f4f92ae4d24788f6fda3f372bcb685c3b981e05cc913774cb35d095751e0cce3",
                "md5": "20fa5b06bb14bb7dbf46ba52a10eb7a3",
                "sha256": "dce0f445141ce96983b06381ba7ab49b66778aa9a64984b2862ff9e095a06655"
            },
            "downloads": -1,
            "filename": "databasez-0.7.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "20fa5b06bb14bb7dbf46ba52a10eb7a3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 33555,
            "upload_time": "2024-01-24T18:53:19",
            "upload_time_iso_8601": "2024-01-24T18:53:19.713903Z",
            "url": "https://files.pythonhosted.org/packages/f4/f9/2ae4d24788f6fda3f372bcb685c3b981e05cc913774cb35d095751e0cce3/databasez-0.7.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bd4806b7040acd7b7b43ae66054a54ae0fd10d2bcda5a0a533a3fab6f85ba8cb",
                "md5": "f128b6003ab183f69bd42233bfdfde20",
                "sha256": "14015728cd7cf39f4a8ec64bced5e915768dac4c5074e778a31843c9a086be84"
            },
            "downloads": -1,
            "filename": "databasez-0.7.2.tar.gz",
            "has_sig": false,
            "md5_digest": "f128b6003ab183f69bd42233bfdfde20",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 20681,
            "upload_time": "2024-01-24T18:53:21",
            "upload_time_iso_8601": "2024-01-24T18:53:21.481107Z",
            "url": "https://files.pythonhosted.org/packages/bd/48/06b7040acd7b7b43ae66054a54ae0fd10d2bcda5a0a533a3fab6f85ba8cb/databasez-0.7.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-24 18:53:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sponsors",
    "github_project": "tarsil",
    "github_not_found": true,
    "lcname": "databasez"
}
        
Elapsed time: 0.21646s