Alchemynger


NameAlchemynger JSON
Version 0.2.1 PyPI version JSON
download
home_pagehttps://github.com/Resheba/Alchemynger
SummarySimple SQLAlchemy connector manager.
upload_time2024-12-07 02:51:15
maintainerNone
docs_urlNone
authorResheba
requires_python>=3.9
licenseNone
keywords sqlalchemy sql database
VCS
bugtrack_url
requirements greenlet sqlalchemy typing-extensions
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <h1 align="center"> Alchemynger </h1>
<h3 align="center"> SQLAlchemy Connection Manager </h3>

<p align="center">
    <img alt="Python" src="https://img.shields.io/badge/python-3.9_|_3.10_|_3.11-blue" />
</p>
<p align="center">
    <img alt="Python" src="https://img.shields.io/badge/python-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54" />
    <img alt="Зostgres" src="https://img.shields.io/badge/postgres-%23316192.svg?style=for-the-badge&logo=postgresql&logoColor=white" />
    <img alt="SQLite" src="https://img.shields.io/badge/sqlite-%2307405e.svg?style=for-the-badge&logo=sqlite&logoColor=white" />
    <img alt="Flask" src="https://img.shields.io/badge/flask-%23000.svg?style=for-the-badge&logo=flask&logoColor=white" />
    <img alt="MySQL" src="https://img.shields.io/badge/mysql-%2300f.svg?style=for-the-badge&logo=mysql&logoColor=white" />
    <img alt="FastAPI" src="https://img.shields.io/badge/FastAPI-005571?style=for-the-badge&logo=fastapi" />
    <img alt="Flask" src="https://img.shields.io/badge/flask-%23000.svg?style=for-the-badge&logo=flask&logoColor=white" />
</p>


Alchemynger is a versatile Python library that simplifies database connectivity and interaction using SQLAlchemy. It offers both synchronous and asynchronous database management for applications that require efficient database operations.


## Installation

You can install Alchemynger using pip:

```bash
pip install alchemynger
```

## Usage

### SyncManager: Synchronous Database Operations

SyncManager is designed for traditional synchronous applications. Here's how to use it:

```python
from alchemynger import SyncManager
from alchemynger.sqlalchemy import Column, String

# Create a SyncManager instance
manager = SyncManager('sqlite:///path/to/db')

# Define your SQLAlchemy model class
class User(manager.Base):
    __tablename__ = 'user'
    name = Column(String(30), primary_key=True)

# Create User table
manager.create_all()

# Create an insert statement and execute it
stmt = manager[User].insert.values(name='username')

manager.execute(stmt, commit=True) # or manager(stmt, commit=True)
```

### AsyncManager: Asynchronous Database Operations

AsyncManager is tailored for asyncio-based applications. Here's how to use it:

```python
from asyncio import run
from alchemynger import AsyncManager
from alchemynger.sqlalchemy import Column, String

# Create an AsyncManager instance
manager = AsyncManager('sqlite+aiosqlite:///path/to/db')

# Define your SQLAlchemy model class
class User(manager.Base):
    __tablename__ = 'user'
    name = Column(String(30), primary_key=True)

# Define an async main function
async def main():
    await manager.create_all()

    stmt = manager[User].insert.values(name='username')

    await manager.execute(stmt, commit=True) # or await manager(stmt, commit=True)

if __name__ == "__main__":
    run(main())
```

### Selector: Useage

Selectors can be used with Columns, a Column, or the Table Model.

```python
# Create a select statements with column or columns
manager[User.name].select
manager[User.name, User.any_col].select
```

```python
# Create statements with model
manager[User].select
manager[User].delete
manager[User].insert
manager[User].update
```
then execute
```python
# execute statement
manager.execute(stmt, scalars=False)
```

## Native use of SQLAlchemy queries
You can also utilize the standard query-writing methods provided by SQLAlchemy, for example, if you find that the library's functionality is insufficient for your needs. Just user `from sqlalchemy import select, insert, ...` or import from `from alchemynger.sqlalchemy import select, insert`

```python
from alchemynger import SyncManager
from alchemynger.sqlalchemy import select, insert, Column, String, Integer

# Create a SyncManager instance
manager = SyncManager('sqlite:///path/to/db')

# Define your SQLAlchemy model class
class User(manager.Base):
    __tablename__ = 'user'
    id = Column(Integer, primary_key=True, autoincrement=True)
    name = Column(String(30))

# Create User table
manager.create_all()

# Create a select statement and execute it

stmt = select(User).where(User.id > 5)

manager.execute(stmt)

# Create an insert statement and execute it
stmt = insert(User).values(name="Lex")

manager.execute(stmt, commit=True) # or manager(stmt, commit=True)
```

### Context Managers and Error Handling

Both SyncManager and AsyncManager provide context managers for managing database sessions. This ensures that sessions are properly closed, even in the event of an exception.

```python
# Example using a context manager
with manager.get_session() as session:
    stmt = manager[User].select

    result = session.execute(stmt)
    # Use the result
```

## Contribution

Contributions to Alchemynger are welcome! If you have ideas for improvements, bug fixes, or new features, please open an issue or submit a pull request on the [GitHub repository](https://github.com/Resheba/Alchemynger).

## License

Alchemynger is licensed under the MIT License. See the [LICENSE](https://github.com/Resheba/Alchemynger/blob/main/LICENSE) file for more details.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Resheba/Alchemynger",
    "name": "Alchemynger",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "SQLAlchemy, SQL, Database",
    "author": "Resheba",
    "author_email": "c90de11@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/43/61/322a93cd00087d01cd13c7e8d67831430c2d00cf43ab57c3b91190105aa4/alchemynger-0.2.1.tar.gz",
    "platform": null,
    "description": "<h1 align=\"center\"> Alchemynger </h1>\n<h3 align=\"center\"> SQLAlchemy Connection Manager </h3>\n\n<p align=\"center\">\n    <img alt=\"Python\" src=\"https://img.shields.io/badge/python-3.9_|_3.10_|_3.11-blue\" />\n</p>\n<p align=\"center\">\n    <img alt=\"Python\" src=\"https://img.shields.io/badge/python-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54\" />\n    <img alt=\"\u0417ostgres\" src=\"https://img.shields.io/badge/postgres-%23316192.svg?style=for-the-badge&logo=postgresql&logoColor=white\" />\n    <img alt=\"SQLite\" src=\"https://img.shields.io/badge/sqlite-%2307405e.svg?style=for-the-badge&logo=sqlite&logoColor=white\" />\n    <img alt=\"Flask\" src=\"https://img.shields.io/badge/flask-%23000.svg?style=for-the-badge&logo=flask&logoColor=white\" />\n    <img alt=\"MySQL\" src=\"https://img.shields.io/badge/mysql-%2300f.svg?style=for-the-badge&logo=mysql&logoColor=white\" />\n    <img alt=\"FastAPI\" src=\"https://img.shields.io/badge/FastAPI-005571?style=for-the-badge&logo=fastapi\" />\n    <img alt=\"Flask\" src=\"https://img.shields.io/badge/flask-%23000.svg?style=for-the-badge&logo=flask&logoColor=white\" />\n</p>\n\n\nAlchemynger is a versatile Python library that simplifies database connectivity and interaction using SQLAlchemy. It offers both synchronous and asynchronous database management for applications that require efficient database operations.\n\n\n## Installation\n\nYou can install Alchemynger using pip:\n\n```bash\npip install alchemynger\n```\n\n## Usage\n\n### SyncManager: Synchronous Database Operations\n\nSyncManager is designed for traditional synchronous applications. Here's how to use it:\n\n```python\nfrom alchemynger import SyncManager\nfrom alchemynger.sqlalchemy import Column, String\n\n# Create a SyncManager instance\nmanager = SyncManager('sqlite:///path/to/db')\n\n# Define your SQLAlchemy model class\nclass User(manager.Base):\n    __tablename__ = 'user'\n    name = Column(String(30), primary_key=True)\n\n# Create User table\nmanager.create_all()\n\n# Create an insert statement and execute it\nstmt = manager[User].insert.values(name='username')\n\nmanager.execute(stmt, commit=True) # or manager(stmt, commit=True)\n```\n\n### AsyncManager: Asynchronous Database Operations\n\nAsyncManager is tailored for asyncio-based applications. Here's how to use it:\n\n```python\nfrom asyncio import run\nfrom alchemynger import AsyncManager\nfrom alchemynger.sqlalchemy import Column, String\n\n# Create an AsyncManager instance\nmanager = AsyncManager('sqlite+aiosqlite:///path/to/db')\n\n# Define your SQLAlchemy model class\nclass User(manager.Base):\n    __tablename__ = 'user'\n    name = Column(String(30), primary_key=True)\n\n# Define an async main function\nasync def main():\n    await manager.create_all()\n\n    stmt = manager[User].insert.values(name='username')\n\n    await manager.execute(stmt, commit=True) # or await manager(stmt, commit=True)\n\nif __name__ == \"__main__\":\n    run(main())\n```\n\n### Selector: Useage\n\nSelectors can be used with Columns, a Column, or the Table Model.\n\n```python\n# Create a select statements with column or columns\nmanager[User.name].select\nmanager[User.name, User.any_col].select\n```\n\n```python\n# Create statements with model\nmanager[User].select\nmanager[User].delete\nmanager[User].insert\nmanager[User].update\n```\nthen execute\n```python\n# execute statement\nmanager.execute(stmt, scalars=False)\n```\n\n## Native use of SQLAlchemy queries\nYou can also utilize the standard query-writing methods provided by SQLAlchemy, for example, if you find that the library's functionality is insufficient for your needs. Just user `from sqlalchemy import select, insert, ...` or import from `from alchemynger.sqlalchemy import select, insert`\n\n```python\nfrom alchemynger import SyncManager\nfrom alchemynger.sqlalchemy import select, insert, Column, String, Integer\n\n# Create a SyncManager instance\nmanager = SyncManager('sqlite:///path/to/db')\n\n# Define your SQLAlchemy model class\nclass User(manager.Base):\n    __tablename__ = 'user'\n    id = Column(Integer, primary_key=True, autoincrement=True)\n    name = Column(String(30))\n\n# Create User table\nmanager.create_all()\n\n# Create a select statement and execute it\n\nstmt = select(User).where(User.id > 5)\n\nmanager.execute(stmt)\n\n# Create an insert statement and execute it\nstmt = insert(User).values(name=\"Lex\")\n\nmanager.execute(stmt, commit=True) # or manager(stmt, commit=True)\n```\n\n### Context Managers and Error Handling\n\nBoth SyncManager and AsyncManager provide context managers for managing database sessions. This ensures that sessions are properly closed, even in the event of an exception.\n\n```python\n# Example using a context manager\nwith manager.get_session() as session:\n    stmt = manager[User].select\n\n    result = session.execute(stmt)\n    # Use the result\n```\n\n## Contribution\n\nContributions to Alchemynger are welcome! If you have ideas for improvements, bug fixes, or new features, please open an issue or submit a pull request on the [GitHub repository](https://github.com/Resheba/Alchemynger).\n\n## License\n\nAlchemynger is licensed under the MIT License. See the [LICENSE](https://github.com/Resheba/Alchemynger/blob/main/LICENSE) file for more details.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Simple SQLAlchemy connector manager.",
    "version": "0.2.1",
    "project_urls": {
        "Homepage": "https://github.com/Resheba/Alchemynger",
        "Repository": "https://github.com/Resheba/Alchemynger"
    },
    "split_keywords": [
        "sqlalchemy",
        " sql",
        " database"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fc2aa4c53a9982556aa2befd52fbaf0591e8b676cebf45af9bc54564c2336bc3",
                "md5": "fb1c7ddd60c39d65997f20adc800ad30",
                "sha256": "d15174221fc8bc4cac14b97f7e95cb0746d2fbc10f6707528ceb9beed514548c"
            },
            "downloads": -1,
            "filename": "alchemynger-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fb1c7ddd60c39d65997f20adc800ad30",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 7765,
            "upload_time": "2024-12-07T02:51:13",
            "upload_time_iso_8601": "2024-12-07T02:51:13.651586Z",
            "url": "https://files.pythonhosted.org/packages/fc/2a/a4c53a9982556aa2befd52fbaf0591e8b676cebf45af9bc54564c2336bc3/alchemynger-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4361322a93cd00087d01cd13c7e8d67831430c2d00cf43ab57c3b91190105aa4",
                "md5": "5894f2be948294073c6b255d112b19ee",
                "sha256": "fd89673cc3a2bb14d8480bb8846c47297162a9143f1991b15a96b4e3e2ba559e"
            },
            "downloads": -1,
            "filename": "alchemynger-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "5894f2be948294073c6b255d112b19ee",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 7156,
            "upload_time": "2024-12-07T02:51:15",
            "upload_time_iso_8601": "2024-12-07T02:51:15.094688Z",
            "url": "https://files.pythonhosted.org/packages/43/61/322a93cd00087d01cd13c7e8d67831430c2d00cf43ab57c3b91190105aa4/alchemynger-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-07 02:51:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Resheba",
    "github_project": "Alchemynger",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "greenlet",
            "specs": [
                [
                    "==",
                    "3.1.1"
                ]
            ]
        },
        {
            "name": "sqlalchemy",
            "specs": [
                [
                    "==",
                    "2.0.36"
                ]
            ]
        },
        {
            "name": "typing-extensions",
            "specs": [
                [
                    "==",
                    "4.12.2"
                ]
            ]
        }
    ],
    "lcname": "alchemynger"
}
        
Elapsed time: 0.52933s