ConnectKit-Database


NameConnectKit-Database JSON
Version 1.3.2 PyPI version JSON
download
home_pageNone
SummaryWrapper for connection to database
upload_time2024-06-10 09:40:38
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseThe MIT License (MIT) Copyright © 2024 MTUCI Open Source Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords connectkit database postgres postgresql mysql sqlite3 sqlite mariadb async asyncio sqlalchemy
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ConnectKit Database [*en*|[ru](./README_RU.md)]

___

ConnectKit Database is a wrapper under SQLAlchemy with some utils.

Include pydantic settings, custom json serializer, template code.

## Installation

___

Three types of connectors are supported:

-[x] PostgreSQL (sync/async)
-[x] MySQL (MariaDB) (sync/async)
-[x] Sqlite3 (sync/async)

By default, the DB connector package is not installed, extensions are specified for installation.

To install sync versions:

```shell
pip install ConnectKit-Database[postgresql]  # Установка коннектора PostgreSQL
pip install ConnectKit-Database[mysql]       # Установка коннектора MySQL/MariaDB
pip install ConnectKit-Database[all]         # Установка всех sync коннекторов
```

To install async versions:

```shell
pip install ConnectKit-Database[asyncpg]        # Установка коннектора PostgreSQL
pip install ConnectKit-Database[aiomysql]       # Установка коннектора MySQL/MariaDB
pip install ConnectKit-Database[aiosqlite]      # Установка коннектора Sqlite3
pip install ConnectKit-Database[asyncall]       # Установка всех async коннекторов
```

## Usage

___

Environment variables are used for connection by default.
Variables are extracted from the environment:

    DB_ADDR=  # Address for default connection to postgres or mysql(mariadb) (default: None)
    DB_PORT=5432  # Port for default connection to postgres or mysql(mariadb)
    DB_ADAPTER=postgresql  # Select default connection dialect (from postgresql, mysql and sqlite)
    DB_USERNAME=postgres  # Username for default connection postgres or mysql(mariadb)
    DB_PASSWORD=  # Username for default connection postgres or mysql(mariadb) (default: None)
    DB_NAME=postgres  # Database for postgres or mysql(mariadb), filepath for sqlite
    DB_POOL_TIMEOUT=1  # Global pool timeout for creating new session to DB
    DB_ECHO: bool = False  # Log all sql statements (for debug purposes)

These variables can be overridden:

```python
from database.settings import settings

settings.DB_ECHO = False
```

**!! Attention !!**
After creating a default connection, changing the settings settings for it is ignored.

To open a connection, the `Database` and `AsyncDatabase` context managers are used:

```python
from database import Database, AsyncDatabase, AsyncSession

with Database() as db:
    db.execute(...)

async with AsyncDatabase() as db:
    await db.execute(...)


# For FastAPI:

async def db_dependency() -> AsyncSession:
    async with AsyncDatabase() as db:
        yield await db.execute(...)
```

The default Base can be used to create models:

```python
from database import Base
from sqlalchemy.orm import Mapped


class Model(Base):
    id: Mapped[int]
```

To initialize ORM models via Base for default connection:

```python
from database import init_default_base, async_init_default_base
from database import Base

init_default_base(Base.metadata)

await async_init_default_base(Base.metadata)
```

## License

___

ConnectKit Database is [MIT License](./LICENSE).
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "ConnectKit-Database",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "connectkit, database, postgres, postgresql, mysql, sqlite3, sqlite, mariadb, async, asyncio, sqlalchemy",
    "author": null,
    "author_email": "RealMetamorph <andr.timchuk@yandex.ru>",
    "download_url": "https://files.pythonhosted.org/packages/f8/d2/a6b3bdfd2675a3006ec601814ed2c576be9ea83de7b5fd305febd3e165af/connectkit_database-1.3.2.tar.gz",
    "platform": null,
    "description": "# ConnectKit Database [*en*|[ru](./README_RU.md)]\n\n___\n\nConnectKit Database is a wrapper under SQLAlchemy with some utils.\n\nInclude pydantic settings, custom json serializer, template code.\n\n## Installation\n\n___\n\nThree types of connectors are supported:\n\n-[x] PostgreSQL (sync/async)\n-[x] MySQL (MariaDB) (sync/async)\n-[x] Sqlite3 (sync/async)\n\nBy default, the DB connector package is not installed, extensions are specified for installation.\n\nTo install sync versions:\n\n```shell\npip install ConnectKit-Database[postgresql]  # \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440\u0430 PostgreSQL\npip install ConnectKit-Database[mysql]       # \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440\u0430 MySQL/MariaDB\npip install ConnectKit-Database[all]         # \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0432\u0441\u0435\u0445 sync \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440\u043e\u0432\n```\n\nTo install async versions:\n\n```shell\npip install ConnectKit-Database[asyncpg]        # \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440\u0430 PostgreSQL\npip install ConnectKit-Database[aiomysql]       # \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440\u0430 MySQL/MariaDB\npip install ConnectKit-Database[aiosqlite]      # \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440\u0430 Sqlite3\npip install ConnectKit-Database[asyncall]       # \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0432\u0441\u0435\u0445 async \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440\u043e\u0432\n```\n\n## Usage\n\n___\n\nEnvironment variables are used for connection by default.\nVariables are extracted from the environment:\n\n    DB_ADDR=  # Address for default connection to postgres or mysql(mariadb) (default: None)\n    DB_PORT=5432  # Port for default connection to postgres or mysql(mariadb)\n    DB_ADAPTER=postgresql  # Select default connection dialect (from postgresql, mysql and sqlite)\n    DB_USERNAME=postgres  # Username for default connection postgres or mysql(mariadb)\n    DB_PASSWORD=  # Username for default connection postgres or mysql(mariadb) (default: None)\n    DB_NAME=postgres  # Database for postgres or mysql(mariadb), filepath for sqlite\n    DB_POOL_TIMEOUT=1  # Global pool timeout for creating new session to DB\n    DB_ECHO: bool = False  # Log all sql statements (for debug purposes)\n\nThese variables can be overridden:\n\n```python\nfrom database.settings import settings\n\nsettings.DB_ECHO = False\n```\n\n**!! Attention !!**\nAfter creating a default connection, changing the settings settings for it is ignored.\n\nTo open a connection, the `Database` and `AsyncDatabase` context managers are used:\n\n```python\nfrom database import Database, AsyncDatabase, AsyncSession\n\nwith Database() as db:\n    db.execute(...)\n\nasync with AsyncDatabase() as db:\n    await db.execute(...)\n\n\n# For FastAPI:\n\nasync def db_dependency() -> AsyncSession:\n    async with AsyncDatabase() as db:\n        yield await db.execute(...)\n```\n\nThe default Base can be used to create models:\n\n```python\nfrom database import Base\nfrom sqlalchemy.orm import Mapped\n\n\nclass Model(Base):\n    id: Mapped[int]\n```\n\nTo initialize ORM models via Base for default connection:\n\n```python\nfrom database import init_default_base, async_init_default_base\nfrom database import Base\n\ninit_default_base(Base.metadata)\n\nawait async_init_default_base(Base.metadata)\n```\n\n## License\n\n___\n\nConnectKit Database is [MIT License](./LICENSE).",
    "bugtrack_url": null,
    "license": "The MIT License (MIT)\n        Copyright \u00a9 2024 MTUCI Open Source\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \u201cSoftware\u201d), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \u201cAS IS\u201d, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Wrapper for connection to database",
    "version": "1.3.2",
    "project_urls": {
        "Homepage": "https://github.com/mtuciru/ConnectKit-Database",
        "Repository": "https://github.com/mtuciru/ConnectKit-Database.git"
    },
    "split_keywords": [
        "connectkit",
        " database",
        " postgres",
        " postgresql",
        " mysql",
        " sqlite3",
        " sqlite",
        " mariadb",
        " async",
        " asyncio",
        " sqlalchemy"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fa47c796e4dd259ccf2fdf1a70d35a2fc5bc9088e85004195116df04ebb78306",
                "md5": "e0cb90ee367a1d0a1be9af03ac99d278",
                "sha256": "7090b2774d4a0a53a8af0372dc36df00d7b694f6cfc7a723c56653a36995b00f"
            },
            "downloads": -1,
            "filename": "connectkit_database-1.3.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e0cb90ee367a1d0a1be9af03ac99d278",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 8698,
            "upload_time": "2024-06-10T09:40:37",
            "upload_time_iso_8601": "2024-06-10T09:40:37.385133Z",
            "url": "https://files.pythonhosted.org/packages/fa/47/c796e4dd259ccf2fdf1a70d35a2fc5bc9088e85004195116df04ebb78306/connectkit_database-1.3.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f8d2a6b3bdfd2675a3006ec601814ed2c576be9ea83de7b5fd305febd3e165af",
                "md5": "d0ab58a14ae0939a7137d4899edff059",
                "sha256": "fc53e5dae831c10b571e64dd437f53cfc9cbf2c912b7e5ed570bd0f9ae22e90a"
            },
            "downloads": -1,
            "filename": "connectkit_database-1.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "d0ab58a14ae0939a7137d4899edff059",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 7096,
            "upload_time": "2024-06-10T09:40:38",
            "upload_time_iso_8601": "2024-06-10T09:40:38.826812Z",
            "url": "https://files.pythonhosted.org/packages/f8/d2/a6b3bdfd2675a3006ec601814ed2c576be9ea83de7b5fd305febd3e165af/connectkit_database-1.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-10 09:40:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mtuciru",
    "github_project": "ConnectKit-Database",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "connectkit-database"
}
        
Elapsed time: 0.27577s