.. contents:: **sqliteschema**
:backlinks: top
:depth: 2
Summary
=======
`sqliteschema <https://github.com/thombashi/sqliteschema>`__ is a Python library to dump table schema of a SQLite database file.
.. image:: https://badge.fury.io/py/sqliteschema.svg
:target: https://badge.fury.io/py/sqliteschema
:alt: PyPI package version
.. image:: https://img.shields.io/pypi/pyversions/sqliteschema.svg
:target: https://pypi.org/project/sqliteschema
:alt: Supported Python versions
.. image:: https://img.shields.io/pypi/implementation/sqliteschema.svg
:target: https://pypi.org/project/sqliteschema
:alt: Supported Python implementations
.. image:: https://github.com/thombashi/sqliteschema/actions/workflows/ci.yml/badge.svg
:target: https://github.com/thombashi/sqliteschema/actions/workflows/ci.yml
:alt: CI status of Linux/macOS/Windows
.. image:: https://coveralls.io/repos/github/thombashi/sqliteschema/badge.svg?branch=master
:target: https://coveralls.io/github/thombashi/sqliteschema?branch=master
:alt: Test coverage
.. image:: https://github.com/thombashi/sqliteschema/actions/workflows/github-code-scanning/codeql/badge.svg
:target: https://github.com/thombashi/sqliteschema/actions/workflows/github-code-scanning/codeql
:alt: CodeQL
Installation
============
Install from PyPI
------------------------------
::
pip install sqliteschema
Install optional dependencies
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
::
pip install sqliteschema[cli] # to use CLI
pip install sqliteschema[dumps] # to use dumps method
pip install sqliteschema[logging] # to use logging
Install from PPA (for Ubuntu)
------------------------------
::
sudo add-apt-repository ppa:thombashi/ppa
sudo apt update
sudo apt install python3-sqliteschema
Usage
=====
Full example source code can be found at `examples/get_table_schema.py <https://github.com/thombashi/sqliteschema/blob/master/examples/get_table_schema.py>`__
Extract SQLite Schemas as dict
----------------------------------
:Sample Code:
.. code:: python
import json
import sqliteschema
extractor = sqliteschema.SQLiteSchemaExtractor(sqlite_db_path)
print(
"--- dump all of the table schemas into a dictionary ---\n{}\n".format(
json.dumps(extractor.fetch_database_schema_as_dict(), indent=4)
)
)
print(
"--- dump a specific table schema into a dictionary ---\n{}\n".format(
json.dumps(extractor.fetch_table_schema("sampletable1").as_dict(), indent=4)
)
)
:Output:
.. code::
--- dump all of the table schemas into a dictionary ---
{
"sampletable0": [
{
"Field": "attr_a",
"Index": false,
"Type": "INTEGER",
"Nullable": "YES",
"Key": "",
"Default": "NULL",
"Extra": ""
},
{
"Field": "attr_b",
"Index": false,
"Type": "INTEGER",
"Nullable": "YES",
"Key": "",
"Default": "NULL",
"Extra": ""
}
],
"sampletable1": [
{
"Field": "foo",
"Index": true,
"Type": "INTEGER",
"Nullable": "YES",
"Key": "",
"Default": "NULL",
"Extra": ""
},
{
"Field": "bar",
"Index": false,
"Type": "REAL",
"Nullable": "YES",
"Key": "",
"Default": "NULL",
"Extra": ""
},
{
"Field": "hoge",
"Index": true,
"Type": "TEXT",
"Nullable": "YES",
"Key": "",
"Default": "NULL",
"Extra": ""
}
],
"constraints": [
{
"Field": "primarykey_id",
"Index": true,
"Type": "INTEGER",
"Nullable": "YES",
"Key": "PRI",
"Default": "NULL",
"Extra": ""
},
{
"Field": "notnull_value",
"Index": false,
"Type": "REAL",
"Nullable": "NO",
"Key": "",
"Default": "",
"Extra": ""
},
{
"Field": "unique_value",
"Index": true,
"Type": "INTEGER",
"Nullable": "YES",
"Key": "UNI",
"Default": "NULL",
"Extra": ""
}
]
}
--- dump a specific table schema into a dictionary ---
{
"sampletable1": [
{
"Field": "foo",
"Index": true,
"Type": "INTEGER",
"Nullable": "YES",
"Key": "",
"Default": "NULL",
"Extra": ""
},
{
"Field": "bar",
"Index": false,
"Type": "REAL",
"Nullable": "YES",
"Key": "",
"Default": "NULL",
"Extra": ""
},
{
"Field": "hoge",
"Index": true,
"Type": "TEXT",
"Nullable": "YES",
"Key": "",
"Default": "NULL",
"Extra": ""
}
]
}
Extract SQLite Schemas as Tabular Text
--------------------------------------------------------------------
Table schemas can be output with the ``dumps`` method.
The ``dumps`` method requires an additional package that can be installed as follows:
::
pip install sqliteschema[dumps]
Usage is as follows:
:Sample Code:
.. code:: python
import sqliteschema
extractor = sqliteschema.SQLiteSchemaExtractor(sqlite_db_path)
for verbosity_level in range(2):
print("--- dump all of the table schemas with a tabular format: verbosity_level={} ---".format(
verbosity_level))
print(extractor.dumps(output_format="markdown", verbosity_level=verbosity_level))
for verbosity_level in range(2):
print("--- dump a specific table schema with a tabular format: verbosity_level={} ---".format(
verbosity_level))
print(extractor.fetch_table_schema("sampletable1").dumps(
output_format="markdown", verbosity_level=verbosity_level))
:Output:
.. code::
--- dump all of the table schemas with a tabular format: verbosity_level=0 ---
# sampletable0
| Field | Type |
| ------ | ------- |
| attr_a | INTEGER |
| attr_b | INTEGER |
# sampletable1
| Field | Type |
| ----- | ------- |
| foo | INTEGER |
| bar | REAL |
| hoge | TEXT |
# constraints
| Field | Type |
| ------------- | ------- |
| primarykey_id | INTEGER |
| notnull_value | REAL |
| unique_value | INTEGER |
--- dump all of the table schemas with a tabular format: verbosity_level=1 ---
# sampletable0
| Field | Type | Nullable | Key | Default | Index | Extra |
| ------ | ------- | -------- | --- | ------- | :---: | ----- |
| attr_a | INTEGER | YES | | NULL | | |
| attr_b | INTEGER | YES | | NULL | | |
# sampletable1
| Field | Type | Nullable | Key | Default | Index | Extra |
| ----- | ------- | -------- | --- | ------- | :---: | ----- |
| foo | INTEGER | YES | | NULL | X | |
| bar | REAL | YES | | NULL | | |
| hoge | TEXT | YES | | NULL | X | |
# constraints
| Field | Type | Nullable | Key | Default | Index | Extra |
| ------------- | ------- | -------- | --- | ------- | :---: | ----- |
| primarykey_id | INTEGER | YES | PRI | NULL | X | |
| notnull_value | REAL | NO | | | | |
| unique_value | INTEGER | YES | UNI | NULL | X | |
--- dump a specific table schema with a tabular format: verbosity_level=0 ---
# sampletable1
| Field | Type |
| ----- | ------- |
| foo | INTEGER |
| bar | REAL |
| hoge | TEXT |
--- dump a specific table schema with a tabular format: verbosity_level=1 ---
# sampletable1
| Field | Type | Nullable | Key | Default | Index | Extra |
| ----- | ------- | -------- | --- | ------- | :---: | ----- |
| foo | INTEGER | YES | | NULL | X | |
| bar | REAL | YES | | NULL | | |
| hoge | TEXT | YES | | NULL | X | |
CLI Usage
----------------------------------
:Sample Code:
.. code:: console
pip install --upgrade sqliteschema[cli]
python3 -m sqliteschema <PATH/TO/SQLITE_FILE>
Dependencies
============
- Python 3.7+
- `Python package dependencies (automatically installed) <https://github.com/thombashi/sqliteschema/network/dependencies>`__
Optional dependencies
----------------------------------
- `loguru <https://github.com/Delgan/loguru>`__
- Used for logging if the package installed
- `pytablewriter <https://github.com/thombashi/pytablewriter>`__
- Required when getting table schemas with tabular text by ``dumps`` method
Raw data
{
"_id": null,
"home_page": "https://github.com/thombashi/sqliteschema",
"name": "sqliteschema",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "SQLite,library,schema",
"author": "Tsuyoshi Hombashi",
"author_email": "tsuyoshi.hombashi@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/29/e7/4482eebf6d8ff7923bb3fd0e9239d3e634f67125cfda3001c88506b939b9/sqliteschema-2.0.0.tar.gz",
"platform": null,
"description": ".. contents:: **sqliteschema**\n :backlinks: top\n :depth: 2\n\n\nSummary\n=======\n`sqliteschema <https://github.com/thombashi/sqliteschema>`__ 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 <https://github.com/thombashi/sqliteschema/blob/master/examples/get_table_schema.py>`__\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 <PATH/TO/SQLITE_FILE>\n\n\nDependencies\n============\n- Python 3.7+\n- `Python package dependencies (automatically installed) <https://github.com/thombashi/sqliteschema/network/dependencies>`__\n\nOptional dependencies\n----------------------------------\n- `loguru <https://github.com/Delgan/loguru>`__\n - Used for logging if the package installed\n- `pytablewriter <https://github.com/thombashi/pytablewriter>`__\n - Required when getting table schemas with tabular text by ``dumps`` method\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "A Python library to dump table schema of a SQLite database file.",
"version": "2.0.0",
"project_urls": {
"Changlog": "https://github.com/thombashi/sqliteschema/releases",
"Homepage": "https://github.com/thombashi/sqliteschema",
"Source": "https://github.com/thombashi/sqliteschema",
"Tracker": "https://github.com/thombashi/sqliteschema/issues"
},
"split_keywords": [
"sqlite",
"library",
"schema"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "878b2ca6e8aa73716547f97f9c8d7b4a3b320e904b2afd49ad0f5d304348cdef",
"md5": "7779a6037abb49bbabb14e1a0cdfc983",
"sha256": "29e0a3e0d5dd8f21e06816850e5d171bfa61155ddabfb2e7422b73215b033714"
},
"downloads": -1,
"filename": "sqliteschema-2.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7779a6037abb49bbabb14e1a0cdfc983",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 14330,
"upload_time": "2023-11-25T15:14:09",
"upload_time_iso_8601": "2023-11-25T15:14:09.486923Z",
"url": "https://files.pythonhosted.org/packages/87/8b/2ca6e8aa73716547f97f9c8d7b4a3b320e904b2afd49ad0f5d304348cdef/sqliteschema-2.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "29e74482eebf6d8ff7923bb3fd0e9239d3e634f67125cfda3001c88506b939b9",
"md5": "b7fd543b82ad709f70cdc06c4ec8639a",
"sha256": "fe6cedddf10de8934ec1ace8319340a2256667e4a1a36f3da4fd1c0956124dc8"
},
"downloads": -1,
"filename": "sqliteschema-2.0.0.tar.gz",
"has_sig": false,
"md5_digest": "b7fd543b82ad709f70cdc06c4ec8639a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 20258,
"upload_time": "2023-11-25T15:14:12",
"upload_time_iso_8601": "2023-11-25T15:14:12.300859Z",
"url": "https://files.pythonhosted.org/packages/29/e7/4482eebf6d8ff7923bb3fd0e9239d3e634f67125cfda3001c88506b939b9/sqliteschema-2.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-25 15:14:12",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "thombashi",
"github_project": "sqliteschema",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "sqliteschema"
}