alchemyrohan


Namealchemyrohan JSON
Version 0.5.0 PyPI version JSON
download
home_pageNone
SummaryIs a helpful tool for creating SqlAlchemy models.
upload_time2024-04-21 12:35:23
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT License Copyright (c) 2023 Alan Wamberger 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 alchemyrohan database sqlalchemy models help-tool
VCS
bugtrack_url
requirements sqlalchemy oracledb
Travis-CI No Travis.
coveralls test coverage No coveralls.
            


# Alchemyrohan

 ![pypi v22|v23](https://img.shields.io/badge/pypi-v22_|_v23-yellow) ![Python 3.10|3.11|3.12](https://img.shields.io/badge/python-3.10_|_3.11_|_3.12-blue) ![SqlAlchemy](https://img.shields.io/badge/SqlAlchemy-2.0-red)


Alchemyrohan is a helpful tool for creating **[SqlAlchemy](https://www.sqlalchemy.org/)** models 
based on the database schema.

---

## ๐Ÿ“– Content

- [How to Install](#-How-to-Install)
- [Database Support](#-Database-Support)
- [How to use](#-How-to-use)
  - [In Command-Line](#-In-Command-Line)
  - [As Script](#-As-Script)
    - [Functions](#-Functions)
      - [Main Function](#-Main-Function)
      - [Optional Function](#-Optional-Function)
- [Models](#-Models)
- [Dependencies](#-Dependencies)
- [Important Note](#Important-Note)
- [Release Notes](#-Release-Notes)
- [License](#-License-and-Third-Party-Licenses)

---


## ๐Ÿ”ง How to Install

With pip package installer from **[PyPI](https://pypi.org/project/pip/)** directly:

```
pip install alchemyrohan
```

or from source:

```
pip install pdm
git clone https://github.com/wamberger/alchemyrohan.git
pdm install
```


## ๐Ÿ—„ Database Support

This project is currently designed to work with the following databases:

- **SqLite**
- **Oracle**


## ๐Ÿ”จ How to use

### โŒจ๏ธ In Command-Line

You can execute the tool by entering the command along with its arguments:

```bash

usage: arohan [-h] -c CONN_STR [-p PATH] [-y PY_PATH] -m MODELS

options:
  -h, --help            show the help message and exit
  -c CONN_STR, --conn_str CONN_STR
                        Connection string to connect with the database - Required argument. 
                        Accepts a string.
  -p PATH, --path PATH  Path where to save the models - Optional argument. 
                        Defaults to the current working directory. Accepts a string.
  -y PY_PATH, --py_path PY_PATH
                        Pythonic path to models in the project. Optional argument. 
                        Defaults to 'py_path'. Accepts a string.
  -m MODELS, --models MODELS
                        Names of the database tables. Required argument. Add every table with -m=

```
**Example:**

```bash 

arohan -c=sqlite:////path/to/your/database/test.db  -y=py.path.to.models -p=path/to/models/ -m=table1 -m=table2 -m=tables3

```


### ๐Ÿ’ป As Script 

You can find an example script in the directory *[help_file/][1]*.

[1]: https://github.com/wamberger/alchemyrohan/tree/master/help_file

#### ๐Ÿช„ Functions

##### ๐Ÿ”ฎ Main Function

**assemble_models()** is the main function. This function is used to create a 
SqlAlchemy database model and is accepting the following arguments:
 
| argument      | description |
|---------------| --------- |
| *conn_str*    | Credential string to connect to the database |
| *table_names* | Names of the tables |
| *path*        | Absolute path to the location where the created models will be saved |
| *py_path*     | pythonic path to the models |

**Simple example how to use the function *assemble_models()*:**

~~~python


import os

from sqlalchemy.exc import SQLAlchemyError
import alchemyrohan as ar


def main() -> None:

    path = os.path.dirname(__file__)

    # Sqlite example
    conn_str = f"sqlite:///{path}{os.sep}test_sqlite{os.sep}test.db"
    # Oracle-Database example
    # db_creds = f'oracle+oracledb://{username}:{password}@{hostname}:{port}/{service_name}'

    path = os.path.join(path, 'test_models') # path to save models
    py_path = 'tests.test_models' # pythonic path to models

    table_names = ['parent', 'child'] # all names will be capitilized

    try:
        ar.assemble_models(conn_str, table_names, path, py_path)
    except SQLAlchemyError as e:
        raise SQLAlchemyError(e) from e


if __name__ == '__main__':
    main()


~~~

##### ๐Ÿ’‰ Optional Function

**get_model():** It retrieves the desired database object of the SqlAlchemy model. It requires the *table_name* and *py_path_to_model* arguments.

~~~python

import alchemyrohan as ar

model = ar.get_model('child', 'py.path.to.model')

~~~

## ๐Ÿ—‚ Models

Created SqlAlchemy models have some additional features:

- Default values.
- Parent-child relationships.
- When 'printing', the string will contain the model/object name and attribute names with their values.

All models are named with the same convention as they are in the database, 
with one difference: they are capitalized according to Python class naming conventions.


**Example of one created model**:

~~~python


from sqlalchemy import Column
from tests.test_models import Base
from sqlalchemy import ForeignKey
from sqlalchemy.dialects.sqlite import INTEGER
from sqlalchemy.dialects.sqlite import TEXT
from sqlalchemy.orm import relationship


class Child(Base):
    __tablename__ = 'child'


    id = Column(INTEGER, primary_key=True)
    parent_id = Column(INTEGER, ForeignKey('parent.id'), nullable=True, default=None)
    name = Column(TEXT, nullable=True, default=None)
    grade = Column(INTEGER, nullable=True, default=None)


    parent_Parent = relationship("Parent", back_populates="children_Child", lazy="joined")
    
    def __str__(self):

        return (f'User(id={self.id},'
			f'parent_id={self.parent_id},'
			f'name={self.name},'
			f'grade={self.grade})')

~~~ 


## ๐Ÿ“š Dependencies

- **sqlalchemy** (version 2.x.x) is an ORM and provides code for its models.
- **oracledb** (version 2.x.x) is used to shape a database table model with an Oracle table schema.


## โ—Important Note

You should always check the code and correct it manually if necessary. 
This may be necessary in cases when:

- You add the wrong path.

- You are creating only one model which has relationships to other tables, 
 thus you will need to create those models or delete the relevant part of the code.

- Your tables have no primary keys. SQLAlchemy requires at least one primary key.

- Your database may have some data types or features which have not yet been tested - Please report!


## ๐Ÿ“‹ Release Notes

- ***v0.5.0***:
  - code refactor.
  - The 'validate' method has been removed from the created models and is no longer available.
  - Updated README.md.

- ***v0.4.1*** - Some vital changes! Please look at CHANGELOG.md. In short:
  - New command-line: *arohan*.
  - Removed functions: *is_model()*, *reload_module()*, *is_module()*.
  - Changing parameter names in the function *assemble_models()*.
  - Bug fixing (*relationship*).
  - In models, method *validate*.

- ***v0.4.0*** - Main update! Not compatible with previous versions. Changes:
  - Changed function name from *assemble_model()* to *assemble_models()*.
  - Updated parameters of the *assemble_models()* function.
  - Revised code structure of the *assemble_models()* function.
  - Adjusted naming or added text in *utils.py*, *wizard.py* and *__init__py*.
  - Updated README.md file.
- ***v0.3.2*** - text fixing and adding third party licenses
- ***v0.3.1*** - bug fixing
- ***v0.3.0*** - added additional functions
- ***v0.2.0*** - tested with Oracle database
- ***v0.1.0*** - creation of the initial code and tested with SqLite database


## ๐Ÿ“„ License and Third-Party Licenses

Alchemyrohan is MIT licensed, as stated in the [LICENSE][2] file.

The following software components are included in this project:

* SqlAlchemy (MIT License)
* python-oracledb (Apache License 2.0) 

[THIRD PARTY LICENSES][3]


[2]: https://github.com/wamberger/alchemyrohan/blob/master/LICENSE
[3]: https://github.com/wamberger/alchemyrohan/blob/master/THIRD_PARTY_LICENSES
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "alchemyrohan",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "alchemyrohan, database, SQLAlchemy, models, help-tool",
    "author": null,
    "author_email": "Alan Wamberger <awamberger@proton.me>",
    "download_url": "https://files.pythonhosted.org/packages/a9/e1/6e50ad952b5cf3b42fed9ebe454809fcb9f0ea2824ee9c5d4bab98445337/alchemyrohan-0.5.0.tar.gz",
    "platform": null,
    "description": "\n\n\n# Alchemyrohan\n\n ![pypi v22|v23](https://img.shields.io/badge/pypi-v22_|_v23-yellow) ![Python 3.10|3.11|3.12](https://img.shields.io/badge/python-3.10_|_3.11_|_3.12-blue) ![SqlAlchemy](https://img.shields.io/badge/SqlAlchemy-2.0-red)\n\n\nAlchemyrohan is a helpful tool for creating **[SqlAlchemy](https://www.sqlalchemy.org/)** models \nbased on the database schema.\n\n---\n\n## \ud83d\udcd6 Content\n\n- [How to Install](#-How-to-Install)\n- [Database Support](#-Database-Support)\n- [How to use](#-How-to-use)\n  - [In Command-Line](#-In-Command-Line)\n  - [As Script](#-As-Script)\n    - [Functions](#-Functions)\n      - [Main Function](#-Main-Function)\n      - [Optional Function](#-Optional-Function)\n- [Models](#-Models)\n- [Dependencies](#-Dependencies)\n- [Important Note](#Important-Note)\n- [Release Notes](#-Release-Notes)\n- [License](#-License-and-Third-Party-Licenses)\n\n---\n\n\n## \ud83d\udd27 How to Install\n\nWith pip package installer from **[PyPI](https://pypi.org/project/pip/)** directly:\n\n```\npip install alchemyrohan\n```\n\nor from source:\n\n```\npip install pdm\ngit clone https://github.com/wamberger/alchemyrohan.git\npdm install\n```\n\n\n## \ud83d\uddc4 Database Support\n\nThis project is currently designed to work with the following databases:\n\n- **SqLite**\n- **Oracle**\n\n\n## \ud83d\udd28 How to use\n\n### \u2328\ufe0f In Command-Line\n\nYou can execute the tool by entering the command along with its arguments:\n\n```bash\n\nusage: arohan [-h] -c CONN_STR [-p PATH] [-y PY_PATH] -m MODELS\n\noptions:\n  -h, --help            show the help message and exit\n  -c CONN_STR, --conn_str CONN_STR\n                        Connection string to connect with the database - Required argument. \n                        Accepts a string.\n  -p PATH, --path PATH  Path where to save the models - Optional argument. \n                        Defaults to the current working directory. Accepts a string.\n  -y PY_PATH, --py_path PY_PATH\n                        Pythonic path to models in the project. Optional argument. \n                        Defaults to 'py_path'. Accepts a string.\n  -m MODELS, --models MODELS\n                        Names of the database tables. Required argument. Add every table with -m=\n\n```\n**Example:**\n\n```bash \n\narohan -c=sqlite:////path/to/your/database/test.db  -y=py.path.to.models -p=path/to/models/ -m=table1 -m=table2 -m=tables3\n\n```\n\n\n### \ud83d\udcbb As Script \n\nYou can find an example script in the directory *[help_file/][1]*.\n\n[1]: https://github.com/wamberger/alchemyrohan/tree/master/help_file\n\n#### \ud83e\ude84 Functions\n\n##### \ud83d\udd2e Main Function\n\n**assemble_models()** is the main function. This function is used to create a \nSqlAlchemy database model and is accepting the following arguments:\n \n| argument      | description |\n|---------------| --------- |\n| *conn_str*    | Credential string to connect to the database |\n| *table_names* | Names of the tables |\n| *path*        | Absolute path to the location where the created models will be saved |\n| *py_path*     | pythonic path to the models |\n\n**Simple example how to use the function *assemble_models()*:**\n\n~~~python\n\n\nimport os\n\nfrom sqlalchemy.exc import SQLAlchemyError\nimport alchemyrohan as ar\n\n\ndef main() -> None:\n\n    path = os.path.dirname(__file__)\n\n    # Sqlite example\n    conn_str = f\"sqlite:///{path}{os.sep}test_sqlite{os.sep}test.db\"\n    # Oracle-Database example\n    # db_creds = f'oracle+oracledb://{username}:{password}@{hostname}:{port}/{service_name}'\n\n    path = os.path.join(path, 'test_models') # path to save models\n    py_path = 'tests.test_models' # pythonic path to models\n\n    table_names = ['parent', 'child'] # all names will be capitilized\n\n    try:\n        ar.assemble_models(conn_str, table_names, path, py_path)\n    except SQLAlchemyError as e:\n        raise SQLAlchemyError(e) from e\n\n\nif __name__ == '__main__':\n    main()\n\n\n~~~\n\n##### \ud83d\udc89 Optional Function\n\n**get_model():** It retrieves the desired database object of the SqlAlchemy model. It requires the *table_name* and *py_path_to_model* arguments.\n\n~~~python\n\nimport alchemyrohan as ar\n\nmodel = ar.get_model('child', 'py.path.to.model')\n\n~~~\n\n## \ud83d\uddc2 Models\n\nCreated SqlAlchemy models have some additional features:\n\n- Default values.\n- Parent-child relationships.\n- When 'printing', the string will contain the model/object name and attribute names with their values.\n\nAll models are named with the same convention as they are in the database, \nwith one difference: they are capitalized according to Python class naming conventions.\n\n\n**Example of one created model**:\n\n~~~python\n\n\nfrom sqlalchemy import Column\nfrom tests.test_models import Base\nfrom sqlalchemy import ForeignKey\nfrom sqlalchemy.dialects.sqlite import INTEGER\nfrom sqlalchemy.dialects.sqlite import TEXT\nfrom sqlalchemy.orm import relationship\n\n\nclass Child(Base):\n    __tablename__ = 'child'\n\n\n    id = Column(INTEGER, primary_key=True)\n    parent_id = Column(INTEGER, ForeignKey('parent.id'), nullable=True, default=None)\n    name = Column(TEXT, nullable=True, default=None)\n    grade = Column(INTEGER, nullable=True, default=None)\n\n\n    parent_Parent = relationship(\"Parent\", back_populates=\"children_Child\", lazy=\"joined\")\n    \n    def __str__(self):\n\n        return (f'User(id={self.id},'\n\t\t\tf'parent_id={self.parent_id},'\n\t\t\tf'name={self.name},'\n\t\t\tf'grade={self.grade})')\n\n~~~ \n\n\n## \ud83d\udcda Dependencies\n\n- **sqlalchemy** (version 2.x.x) is an ORM and provides code for its models.\n- **oracledb** (version 2.x.x) is used to shape a database table model with an Oracle table schema.\n\n\n## \u2757Important Note\n\nYou should always check the code and correct it manually if necessary. \nThis may be necessary in cases when:\n\n- You add the wrong path.\n\n- You are creating only one model which has relationships to other tables, \n thus you will need to create those models or delete the relevant part of the code.\n\n- Your tables have no primary keys. SQLAlchemy requires at least one primary key.\n\n- Your database may have some data types or features which have not yet been tested - Please report!\n\n\n## \ud83d\udccb Release Notes\n\n- ***v0.5.0***:\n  - code refactor.\n  - The 'validate' method has been removed from the created models and is no longer available.\n  - Updated README.md.\n\n- ***v0.4.1*** - Some vital changes! Please look at CHANGELOG.md. In short:\n  - New command-line: *arohan*.\n  - Removed functions: *is_model()*, *reload_module()*, *is_module()*.\n  - Changing parameter names in the function *assemble_models()*.\n  - Bug fixing (*relationship*).\n  - In models, method *validate*.\n\n- ***v0.4.0*** - Main update! Not compatible with previous versions. Changes:\n  - Changed function name from *assemble_model()* to *assemble_models()*.\n  - Updated parameters of the *assemble_models()* function.\n  - Revised code structure of the *assemble_models()* function.\n  - Adjusted naming or added text in *utils.py*, *wizard.py* and *__init__py*.\n  - Updated README.md file.\n- ***v0.3.2*** - text fixing and adding third party licenses\n- ***v0.3.1*** - bug fixing\n- ***v0.3.0*** - added additional functions\n- ***v0.2.0*** - tested with Oracle database\n- ***v0.1.0*** - creation of the initial code and tested with SqLite database\n\n\n## \ud83d\udcc4 License and Third-Party Licenses\n\nAlchemyrohan is MIT licensed, as stated in the [LICENSE][2] file.\n\nThe following software components are included in this project:\n\n* SqlAlchemy (MIT License)\n* python-oracledb (Apache License 2.0) \n\n[THIRD PARTY LICENSES][3]\n\n\n[2]: https://github.com/wamberger/alchemyrohan/blob/master/LICENSE\n[3]: https://github.com/wamberger/alchemyrohan/blob/master/THIRD_PARTY_LICENSES",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Alan Wamberger  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.",
    "summary": "Is a helpful tool for creating SqlAlchemy models.",
    "version": "0.5.0",
    "project_urls": {
        "Changelog": "https://github.com/wamberger/alchemyrohan/blob/master/CHANGELOG.md",
        "Documentation": "https://github.com/wamberger/alchemyrohan/blob/master/README.md",
        "Homepage": "https://github.com/wamberger/alchemyrohan",
        "Repository": "https://github.com/wamberger/alchemyrohan"
    },
    "split_keywords": [
        "alchemyrohan",
        " database",
        " sqlalchemy",
        " models",
        " help-tool"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "94f0b83dab2d508a931c50641ff79d0f275076107ed4aabf2136110e5220d51f",
                "md5": "fee54522ae7d517a3e84730b20f051c4",
                "sha256": "ac589bad311553a668af93dcedf2f3a3dec7d00c7744796c475729ed7993319b"
            },
            "downloads": -1,
            "filename": "alchemyrohan-0.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "fee54522ae7d517a3e84730b20f051c4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 13263,
            "upload_time": "2024-04-21T12:35:20",
            "upload_time_iso_8601": "2024-04-21T12:35:20.721792Z",
            "url": "https://files.pythonhosted.org/packages/94/f0/b83dab2d508a931c50641ff79d0f275076107ed4aabf2136110e5220d51f/alchemyrohan-0.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a9e16e50ad952b5cf3b42fed9ebe454809fcb9f0ea2824ee9c5d4bab98445337",
                "md5": "997b57f7d494b969de0b9d45b3698102",
                "sha256": "cef061050dcf5c71f62a7cb2ebeea4614e9d6af5c723b75ba956c68828917917"
            },
            "downloads": -1,
            "filename": "alchemyrohan-0.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "997b57f7d494b969de0b9d45b3698102",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 1537505,
            "upload_time": "2024-04-21T12:35:23",
            "upload_time_iso_8601": "2024-04-21T12:35:23.558527Z",
            "url": "https://files.pythonhosted.org/packages/a9/e1/6e50ad952b5cf3b42fed9ebe454809fcb9f0ea2824ee9c5d4bab98445337/alchemyrohan-0.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-21 12:35:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "wamberger",
    "github_project": "alchemyrohan",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "sqlalchemy",
            "specs": []
        },
        {
            "name": "oracledb",
            "specs": []
        }
    ],
    "lcname": "alchemyrohan"
}
        
Elapsed time: 3.77639s