sqlalchemy-schemadisplay


Namesqlalchemy-schemadisplay JSON
Version 2.0 PyPI version JSON
download
home_page
SummaryPackage for the generation of diagrams based on SQLAlchemy ORM models and or the database itself
upload_time2024-02-15 11:52:53
maintainer
docs_urlNone
author
requires_python>=3.8
license
keywords aiida workflows lammps
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            sqlalchemy_schemadisplay
========================

Turn SQLAlchemy DB Model into a graph.

.. image:: https://img.shields.io/pypi/v/sqlalchemy_schemadisplay
   :alt: PyPI
   :target: https://pypi.org/project/sqlalchemy_schemadisplay


See `SQLAlchemy wiki <https://github.com/sqlalchemy/sqlalchemy/wiki/SchemaDisplay>`_ for the previous version of this doc.

Usage
=====

You will need atleast SQLAlchemy and pydot along with graphviz for this. Graphviz-cairo is highly recommended to get tolerable image quality. If PIL and an image viewer are available then there are functions to automatically show the image. Some of the stuff, specifically loading list of tables from a database via a mapper and reflecting indexes currently only work on postgres.

This is an example of database entity diagram generation:

.. code-block:: python

    from sqlalchemy import MetaData
    from sqlalchemy_schemadisplay import create_schema_graph

    # create the pydot graph object by autoloading all tables via a bound metadata object
    graph = create_schema_graph(metadata=MetaData('postgres://user:pwd@host/database'),
       show_datatypes=False, # The image would get nasty big if we'd show the datatypes
       show_indexes=False, # ditto for indexes
       rankdir='LR', # From left to right (instead of top to bottom)
       concentrate=False # Don't try to join the relation lines together
    )
    graph.write_png('dbschema.png') # write out the file


And an UML class diagram from a model:

.. code-block:: python

    from myapp import model
    from sqlalchemy_schemadisplay import create_uml_graph
    from sqlalchemy.orm import class_mapper

    # lets find all the mappers in our model
    mappers = [model.__mapper__]
    for attr in dir(model):
        if attr[0] == '_': continue
        try:
            cls = getattr(model, attr)
            mappers.append(cls.property.entity)
        except:
            pass

    # pass them to the function and set some formatting options
    graph = create_uml_graph(mappers,
        show_operations=False, # not necessary in this case
        show_multiplicity_one=False # some people like to see the ones, some don't
    )
    graph.write_png('schema.png') # write out the file


Changelog
=========

2.0 - 2024-02-15
----------------

- Compatibility with SQLAlchemy 2.x [Jonathan Chico]

- Python requirements changed to >= 3.8 [zlopez]

1.4 - 2024-02-15
----------------

Last release to support Python 2.

- Limit SQLAlchemy dependency to < 2.0 to fix installation for Python 2 [abitrolly - Anatoli Babenia]

- Set dir kwarg in Edge instantiation to 'both' in order to show arrow heads and arrow tails.
  [bkrn - Aaron Di Silvestro]

- Add 'show_column_keys' kwarg to 'create_schema_graph' to allow a PK/FK suffix to be added to columns that are primary keys/foreign keys respectively [cchrysostomou - Constantine Chrysostomou]

- Add 'restrict_tables' kwarg to 'create_schema_graph' to restrict the desired tables we want to generate via graphviz and show relationships for [cchrysostomou - Constantine Chrysostomou]


1.3 - 2016-01-27
----------------

- Fix warning about illegal attribute in uml generation by using correct
  attribute.
  [electrocucaracha - Victor Morales]

- Use MIT license
  [fschulze]


1.2 - 2014-03-02
----------------

- Compatibility with SQLAlchemy 0.9.
  [fschulze]

- Compatibility with SQLAlchemy 0.8.
  [Surgo - Kosei Kitahara]

- Leave tables out even when a foreign key points to them but they are not in
  the table list.
  [tiagosab - Tiago Saboga]


1.1 - 2011-10-12
----------------

- New option to skip inherited attributes.
  [nouri]

- Quote class name, because some names like 'Node' confuse dot.
  [nouri - Daniel Nouri]


1.0 - 2011-01-07
----------------

- Initial release
  [fschulze - Florian Schulze]

- Original releases as recipe on SQLAlchemy Wiki by Ants Aasma


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "sqlalchemy-schemadisplay",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "aiida,workflows,lammps",
    "author": "",
    "author_email": "Florian Schulze <florian.schulze@gmx.net>",
    "download_url": "https://files.pythonhosted.org/packages/4f/b0/d4587a6223dd563072ed5d0b94e0d062bb3d019bf16d0e65a85324c49efc/sqlalchemy_schemadisplay-2.0.tar.gz",
    "platform": null,
    "description": "sqlalchemy_schemadisplay\n========================\n\nTurn SQLAlchemy DB Model into a graph.\n\n.. image:: https://img.shields.io/pypi/v/sqlalchemy_schemadisplay\n   :alt: PyPI\n   :target: https://pypi.org/project/sqlalchemy_schemadisplay\n\n\nSee `SQLAlchemy wiki <https://github.com/sqlalchemy/sqlalchemy/wiki/SchemaDisplay>`_ for the previous version of this doc.\n\nUsage\n=====\n\nYou will need atleast SQLAlchemy and pydot along with graphviz for this. Graphviz-cairo is highly recommended to get tolerable image quality. If PIL and an image viewer are available then there are functions to automatically show the image. Some of the stuff, specifically loading list of tables from a database via a mapper and reflecting indexes currently only work on postgres.\n\nThis is an example of database entity diagram generation:\n\n.. code-block:: python\n\n    from sqlalchemy import MetaData\n    from sqlalchemy_schemadisplay import create_schema_graph\n\n    # create the pydot graph object by autoloading all tables via a bound metadata object\n    graph = create_schema_graph(metadata=MetaData('postgres://user:pwd@host/database'),\n       show_datatypes=False, # The image would get nasty big if we'd show the datatypes\n       show_indexes=False, # ditto for indexes\n       rankdir='LR', # From left to right (instead of top to bottom)\n       concentrate=False # Don't try to join the relation lines together\n    )\n    graph.write_png('dbschema.png') # write out the file\n\n\nAnd an UML class diagram from a model:\n\n.. code-block:: python\n\n    from myapp import model\n    from sqlalchemy_schemadisplay import create_uml_graph\n    from sqlalchemy.orm import class_mapper\n\n    # lets find all the mappers in our model\n    mappers = [model.__mapper__]\n    for attr in dir(model):\n        if attr[0] == '_': continue\n        try:\n            cls = getattr(model, attr)\n            mappers.append(cls.property.entity)\n        except:\n            pass\n\n    # pass them to the function and set some formatting options\n    graph = create_uml_graph(mappers,\n        show_operations=False, # not necessary in this case\n        show_multiplicity_one=False # some people like to see the ones, some don't\n    )\n    graph.write_png('schema.png') # write out the file\n\n\nChangelog\n=========\n\n2.0 - 2024-02-15\n----------------\n\n- Compatibility with SQLAlchemy 2.x [Jonathan Chico]\n\n- Python requirements changed to >= 3.8 [zlopez]\n\n1.4 - 2024-02-15\n----------------\n\nLast release to support Python 2.\n\n- Limit SQLAlchemy dependency to < 2.0 to fix installation for Python 2 [abitrolly - Anatoli Babenia]\n\n- Set dir kwarg in Edge instantiation to 'both' in order to show arrow heads and arrow tails.\n  [bkrn - Aaron Di Silvestro]\n\n- Add 'show_column_keys' kwarg to 'create_schema_graph' to allow a PK/FK suffix to be added to columns that are primary keys/foreign keys respectively [cchrysostomou - Constantine Chrysostomou]\n\n- Add 'restrict_tables' kwarg to 'create_schema_graph' to restrict the desired tables we want to generate via graphviz and show relationships for [cchrysostomou - Constantine Chrysostomou]\n\n\n1.3 - 2016-01-27\n----------------\n\n- Fix warning about illegal attribute in uml generation by using correct\n  attribute.\n  [electrocucaracha - Victor Morales]\n\n- Use MIT license\n  [fschulze]\n\n\n1.2 - 2014-03-02\n----------------\n\n- Compatibility with SQLAlchemy 0.9.\n  [fschulze]\n\n- Compatibility with SQLAlchemy 0.8.\n  [Surgo - Kosei Kitahara]\n\n- Leave tables out even when a foreign key points to them but they are not in\n  the table list.\n  [tiagosab - Tiago Saboga]\n\n\n1.1 - 2011-10-12\n----------------\n\n- New option to skip inherited attributes.\n  [nouri]\n\n- Quote class name, because some names like 'Node' confuse dot.\n  [nouri - Daniel Nouri]\n\n\n1.0 - 2011-01-07\n----------------\n\n- Initial release\n  [fschulze - Florian Schulze]\n\n- Original releases as recipe on SQLAlchemy Wiki by Ants Aasma\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Package for the generation of diagrams based on SQLAlchemy ORM models and or the database itself",
    "version": "2.0",
    "project_urls": {
        "Documentation": "https://github.com/fschulze/sqlalchemy_schemadisplay/blob/master/README.rst",
        "Source": "https://github.com/fschulze/sqlalchemy_schemadisplay"
    },
    "split_keywords": [
        "aiida",
        "workflows",
        "lammps"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1f9ea8d5cea8fb842393846ad42596eeb989511fab0aa1c88fe226c24c6355e7",
                "md5": "1cc577e4ff55a98603c673777578b156",
                "sha256": "e4b928e2aec145f72a2b35de7855a78fca5e09ac4d48f2d58b4472cb640cd362"
            },
            "downloads": -1,
            "filename": "sqlalchemy_schemadisplay-2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1cc577e4ff55a98603c673777578b156",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 11377,
            "upload_time": "2024-02-15T11:52:52",
            "upload_time_iso_8601": "2024-02-15T11:52:52.210178Z",
            "url": "https://files.pythonhosted.org/packages/1f/9e/a8d5cea8fb842393846ad42596eeb989511fab0aa1c88fe226c24c6355e7/sqlalchemy_schemadisplay-2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4fb0d4587a6223dd563072ed5d0b94e0d062bb3d019bf16d0e65a85324c49efc",
                "md5": "0515289c080801978d885b9ef382b86c",
                "sha256": "e90b9c9868814975d674a889aadb7c4651658f0e119e1c9320279ea527744d5e"
            },
            "downloads": -1,
            "filename": "sqlalchemy_schemadisplay-2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0515289c080801978d885b9ef382b86c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 11637,
            "upload_time": "2024-02-15T11:52:53",
            "upload_time_iso_8601": "2024-02-15T11:52:53.355658Z",
            "url": "https://files.pythonhosted.org/packages/4f/b0/d4587a6223dd563072ed5d0b94e0d062bb3d019bf16d0e65a85324c49efc/sqlalchemy_schemadisplay-2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-15 11:52:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "fschulze",
    "github_project": "sqlalchemy_schemadisplay",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "sqlalchemy-schemadisplay"
}
        
Elapsed time: 3.67485s