{"id":15050590,"url":"https://github.com/thombashi/sqliteschema","last_synced_at":"2025-07-13T15:34:58.947Z","repository":{"id":54330698,"uuid":"65124352","full_name":"thombashi/sqliteschema","owner":"thombashi","description":"sqliteschema is a Python library to dump table schema of a SQLite database file.","archived":false,"fork":false,"pushed_at":"2025-03-02T03:21:36.000Z","size":431,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-10T02:14:38.485Z","etag":null,"topics":["database-schema","python-library","sqlite"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thombashi.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-08-07T08:52:33.000Z","updated_at":"2025-03-02T03:13:36.000Z","dependencies_parsed_at":"2023-12-15T02:18:05.551Z","dependency_job_id":"ec9c9911-81d3-45a4-998e-583bda67b34f","html_url":"https://github.com/thombashi/sqliteschema","commit_stats":{"total_commits":619,"total_committers":2,"mean_commits":309.5,"dds":0.3150242326332795,"last_synced_commit":"3c0b598fb695430878426fe59f2fc306285849b6"},"previous_names":["thombashi/sqlitestructure"],"tags_count":74,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thombashi%2Fsqliteschema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thombashi%2Fsqliteschema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thombashi%2Fsqliteschema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thombashi%2Fsqliteschema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thombashi","download_url":"https://codeload.github.com/thombashi/sqliteschema/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248142903,"owners_count":21054671,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database-schema","python-library","sqlite"],"created_at":"2024-09-24T21:27:40.574Z","updated_at":"2025-04-10T02:14:47.241Z","avatar_url":"https://github.com/thombashi.png","language":"Python","readme":".. contents:: **sqliteschema**\n   :backlinks: top\n   :depth: 2\n\n\nSummary\n=======\n`sqliteschema \u003chttps://github.com/thombashi/sqliteschema\u003e`__ is a Python library to dump table schema of a SQLite database file.\n\n\n.. image:: https://badge.fury.io/py/sqliteschema.svg\n    :target: https://badge.fury.io/py/sqliteschema\n    :alt: PyPI package version\n\n.. image:: https://img.shields.io/pypi/pyversions/sqliteschema.svg\n    :target: https://pypi.org/project/sqliteschema\n    :alt: Supported Python versions\n\n.. image:: https://img.shields.io/pypi/implementation/sqliteschema.svg\n    :target: https://pypi.org/project/sqliteschema\n    :alt: Supported Python implementations\n\n.. image:: https://github.com/thombashi/sqliteschema/actions/workflows/ci.yml/badge.svg\n    :target: https://github.com/thombashi/sqliteschema/actions/workflows/ci.yml\n    :alt: CI status of Linux/macOS/Windows\n\n.. image:: https://coveralls.io/repos/github/thombashi/sqliteschema/badge.svg?branch=master\n    :target: https://coveralls.io/github/thombashi/sqliteschema?branch=master\n    :alt: Test coverage\n\n.. image:: https://github.com/thombashi/sqliteschema/actions/workflows/github-code-scanning/codeql/badge.svg\n    :target: https://github.com/thombashi/sqliteschema/actions/workflows/github-code-scanning/codeql\n    :alt: CodeQL\n\n\nInstallation\n============\n\nInstall from PyPI\n------------------------------\n::\n\n    pip install sqliteschema\n\nInstall optional dependencies\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n::\n\n    pip install sqliteschema[cli]  # to use CLI\n    pip install sqliteschema[dumps]  # to use dumps method\n    pip install sqliteschema[logging]  # to use logging\n\nInstall from PPA (for Ubuntu)\n------------------------------\n::\n\n    sudo add-apt-repository ppa:thombashi/ppa\n    sudo apt update\n    sudo apt install python3-sqliteschema\n\n\nUsage\n=====\nFull example source code can be found at `examples/get_table_schema.py \u003chttps://github.com/thombashi/sqliteschema/blob/master/examples/get_table_schema.py\u003e`__\n\nExtract SQLite Schemas as dict\n----------------------------------\n:Sample Code:\n    .. code:: python\n\n        import json\n        import sqliteschema\n\n        extractor = sqliteschema.SQLiteSchemaExtractor(sqlite_db_path)\n\n        print(\n            \"--- dump all of the table schemas into a dictionary ---\\n{}\\n\".format(\n                json.dumps(extractor.fetch_database_schema_as_dict(), indent=4)\n            )\n        )\n\n        print(\n            \"--- dump a specific table schema into a dictionary ---\\n{}\\n\".format(\n                json.dumps(extractor.fetch_table_schema(\"sampletable1\").as_dict(), indent=4)\n            )\n        )\n\n:Output:\n    .. code::\n\n        --- dump all of the table schemas into a dictionary ---\n        {\n            \"sampletable0\": [\n                {\n                    \"Field\": \"attr_a\",\n                    \"Index\": false,\n                    \"Type\": \"INTEGER\",\n                    \"Nullable\": \"YES\",\n                    \"Key\": \"\",\n                    \"Default\": \"NULL\",\n                    \"Extra\": \"\"\n                },\n                {\n                    \"Field\": \"attr_b\",\n                    \"Index\": false,\n                    \"Type\": \"INTEGER\",\n                    \"Nullable\": \"YES\",\n                    \"Key\": \"\",\n                    \"Default\": \"NULL\",\n                    \"Extra\": \"\"\n                }\n            ],\n            \"sampletable1\": [\n                {\n                    \"Field\": \"foo\",\n                    \"Index\": true,\n                    \"Type\": \"INTEGER\",\n                    \"Nullable\": \"YES\",\n                    \"Key\": \"\",\n                    \"Default\": \"NULL\",\n                    \"Extra\": \"\"\n                },\n                {\n                    \"Field\": \"bar\",\n                    \"Index\": false,\n                    \"Type\": \"REAL\",\n                    \"Nullable\": \"YES\",\n                    \"Key\": \"\",\n                    \"Default\": \"NULL\",\n                    \"Extra\": \"\"\n                },\n                {\n                    \"Field\": \"hoge\",\n                    \"Index\": true,\n                    \"Type\": \"TEXT\",\n                    \"Nullable\": \"YES\",\n                    \"Key\": \"\",\n                    \"Default\": \"NULL\",\n                    \"Extra\": \"\"\n                }\n            ],\n            \"constraints\": [\n                {\n                    \"Field\": \"primarykey_id\",\n                    \"Index\": true,\n                    \"Type\": \"INTEGER\",\n                    \"Nullable\": \"YES\",\n                    \"Key\": \"PRI\",\n                    \"Default\": \"NULL\",\n                    \"Extra\": \"\"\n                },\n                {\n                    \"Field\": \"notnull_value\",\n                    \"Index\": false,\n                    \"Type\": \"REAL\",\n                    \"Nullable\": \"NO\",\n                    \"Key\": \"\",\n                    \"Default\": \"\",\n                    \"Extra\": \"\"\n                },\n                {\n                    \"Field\": \"unique_value\",\n                    \"Index\": true,\n                    \"Type\": \"INTEGER\",\n                    \"Nullable\": \"YES\",\n                    \"Key\": \"UNI\",\n                    \"Default\": \"NULL\",\n                    \"Extra\": \"\"\n                }\n            ]\n        }\n\n        --- dump a specific table schema into a dictionary ---\n        {\n            \"sampletable1\": [\n                {\n                    \"Field\": \"foo\",\n                    \"Index\": true,\n                    \"Type\": \"INTEGER\",\n                    \"Nullable\": \"YES\",\n                    \"Key\": \"\",\n                    \"Default\": \"NULL\",\n                    \"Extra\": \"\"\n                },\n                {\n                    \"Field\": \"bar\",\n                    \"Index\": false,\n                    \"Type\": \"REAL\",\n                    \"Nullable\": \"YES\",\n                    \"Key\": \"\",\n                    \"Default\": \"NULL\",\n                    \"Extra\": \"\"\n                },\n                {\n                    \"Field\": \"hoge\",\n                    \"Index\": true,\n                    \"Type\": \"TEXT\",\n                    \"Nullable\": \"YES\",\n                    \"Key\": \"\",\n                    \"Default\": \"NULL\",\n                    \"Extra\": \"\"\n                }\n            ]\n        }\n\n\nExtract SQLite Schemas as Tabular Text\n--------------------------------------------------------------------\nTable schemas can be output with the ``dumps`` method.\nThe ``dumps`` method requires an additional package that can be installed as follows:\n\n::\n\n    pip install sqliteschema[dumps]\n\nUsage is as follows:\n\n:Sample Code:\n    .. code:: python\n\n        import sqliteschema\n\n        extractor = sqliteschema.SQLiteSchemaExtractor(sqlite_db_path)\n\n        for verbosity_level in range(2):\n            print(\"--- dump all of the table schemas with a tabular format: verbosity_level={} ---\".format(\n                verbosity_level))\n            print(extractor.dumps(output_format=\"markdown\", verbosity_level=verbosity_level))\n\n        for verbosity_level in range(2):\n            print(\"--- dump a specific table schema with a tabular format: verbosity_level={} ---\".format(\n                verbosity_level))\n            print(extractor.fetch_table_schema(\"sampletable1\").dumps(\n                output_format=\"markdown\", verbosity_level=verbosity_level))\n\n:Output:\n    .. code::\n\n        --- dump all of the table schemas with a tabular format: verbosity_level=0 ---\n        # sampletable0\n        | Field  |  Type   |\n        | ------ | ------- |\n        | attr_a | INTEGER |\n        | attr_b | INTEGER |\n\n        # sampletable1\n        | Field |  Type   |\n        | ----- | ------- |\n        | foo   | INTEGER |\n        | bar   | REAL    |\n        | hoge  | TEXT    |\n\n        # constraints\n        |     Field     |  Type   |\n        | ------------- | ------- |\n        | primarykey_id | INTEGER |\n        | notnull_value | REAL    |\n        | unique_value  | INTEGER |\n\n        --- dump all of the table schemas with a tabular format: verbosity_level=1 ---\n        # sampletable0\n        | Field  |  Type   | Nullable | Key | Default | Index | Extra |\n        | ------ | ------- | -------- | --- | ------- | :---: | ----- |\n        | attr_a | INTEGER | YES      |     | NULL    |       |       |\n        | attr_b | INTEGER | YES      |     | NULL    |       |       |\n\n        # sampletable1\n        | Field |  Type   | Nullable | Key | Default | Index | Extra |\n        | ----- | ------- | -------- | --- | ------- | :---: | ----- |\n        | foo   | INTEGER | YES      |     | NULL    |   X   |       |\n        | bar   | REAL    | YES      |     | NULL    |       |       |\n        | hoge  | TEXT    | YES      |     | NULL    |   X   |       |\n\n        # constraints\n        |     Field     |  Type   | Nullable | Key | Default | Index | Extra |\n        | ------------- | ------- | -------- | --- | ------- | :---: | ----- |\n        | primarykey_id | INTEGER | YES      | PRI | NULL    |   X   |       |\n        | notnull_value | REAL    | NO       |     |         |       |       |\n        | unique_value  | INTEGER | YES      | UNI | NULL    |   X   |       |\n\n        --- dump a specific table schema with a tabular format: verbosity_level=0 ---\n        # sampletable1\n        | Field |  Type   |\n        | ----- | ------- |\n        | foo   | INTEGER |\n        | bar   | REAL    |\n        | hoge  | TEXT    |\n\n        --- dump a specific table schema with a tabular format: verbosity_level=1 ---\n        # sampletable1\n        | Field |  Type   | Nullable | Key | Default | Index | Extra |\n        | ----- | ------- | -------- | --- | ------- | :---: | ----- |\n        | foo   | INTEGER | YES      |     | NULL    |   X   |       |\n        | bar   | REAL    | YES      |     | NULL    |       |       |\n        | hoge  | TEXT    | YES      |     | NULL    |   X   |       |\n\n\nCLI Usage\n----------------------------------\n\n:Sample Code:\n    .. code:: console\n\n        pip install --upgrade sqliteschema[cli]\n        python3 -m sqliteschema \u003cPATH/TO/SQLITE_FILE\u003e\n\n\nDependencies\n============\n- Python 3.9+\n- `Python package dependencies (automatically installed) \u003chttps://github.com/thombashi/sqliteschema/network/dependencies\u003e`__\n\nOptional dependencies\n----------------------------------\n- `loguru \u003chttps://github.com/Delgan/loguru\u003e`__\n    - Used for logging if the package installed\n- `pytablewriter \u003chttps://github.com/thombashi/pytablewriter\u003e`__\n    - Required when getting table schemas with tabular text by ``dumps`` method\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthombashi%2Fsqliteschema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthombashi%2Fsqliteschema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthombashi%2Fsqliteschema/lists"}