Skip to main content

Python library to do introspection in Sqlite/Spatialite databases.

Useful to get the table names, the column names of a specific table, the available geometry columns, etc, without needing to dig in SQL.

Installation

pip install spatialiteintrospect

Dependences

spatialite-introspect uses sqlite3, which should be included in any Python distribution since version 2.5.

Usage

Basic usage:

import spatialiteintrospect as spintrospect

# open db connection
db = spintrospect.connect("mydb.sqlite")

# get all the tables in the db
db.get_tables()
# The result is an array of table names, e.g.: ['tbl1', 'tbl2', 'tbl3']

# finally, we need to close the database
db.close()

Available methods:

# get all the tables in the db
db.get_tables()
# The result is an array of table names, e.g.: ['tbl1', 'tbl2', 'tbl3']

# get all the tables that contain at least one geometry field
db.get_geometry_tables()
# The result is an array of table names, e.g.: ['tbl1', 'tbl3']

# get the geometry columns of a specific table
db.get_geometry_columns("tbl1")
# The result is an array of column names, e.g.: ['the_point_geom', 'the_line_geom']

# get the geometry columns of a specific tables, plus some information about the table containing it
db.get_geometry_columns_info("tbl1")
# The result is an array of tuples such as
#     [
#         ('tbl1', 'the_point_geom', 2, 4326, 1, ['fid'], ['fid', 'title', 'the_point_geom', 'the_line_geom']),
#         ('tbl1', 'the_line_geom', 2, 4326, 2, ['fid'], ['fid', 'title', 'the_point_geom', 'the_line_geom'])
#     ]
# The contents of each tuple is: (table_name, geom_column, coord_dimension, srid, geometry_type, key_columns, fields)

# It also works with no table filter:
db.get_geometry_columns_info()
# Result:
#     [
#         ('tbl1', 'the_point_geom', 2, 4326, 1, ['fid'], ['fid', 'title', 'the_point_geom', 'the_line_geom']),
#         ('tbl1', 'the_line_geom', 2, 4326, 2, ['fid'], ['fid', 'title', 'the_point_geom', 'the_line_geom']),
#         ('tbl3', 'geom', 2, 4326, 1, ['fid'], ['fid', 'author', 'date', 'geom'])
#     ]

# get the primary column(s) of a table
db.get_pk_columns("tbl2")
# The result is an array of the fields that compose the PK: ['country_cd', 'region_cd']

# get all the fields of a table
db.get_fields("tbl1")
# The result is an array of field names such as ['fid', 'title', 'the_point_geom', 'the_line_geom']

Note that the library expects Unicode strings on all the string params. Non unicode strings are also accepted if using ASCII-only characters.

Authors

Cesar Martinez Izquierdo - Scolab

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spatialiteintrospect-1.2.tar.gz (452.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spatialiteintrospect-1.2-py2.py3-none-any.whl (6.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file spatialiteintrospect-1.2.tar.gz.

File metadata

File hashes

Hashes for spatialiteintrospect-1.2.tar.gz
Algorithm Hash digest
SHA256 82e114960d628e40771611e2e24fd688c81e87a338d2e4eb93be0bc7f5e8cce4
MD5 94b1eb13cb031f953755f71a9ff3bd2d
BLAKE2b-256 111549855c9ec6a4a799575c5e7ac8e0609c0f29221eac9c0b69d91bbe043c8a

See more details on using hashes here.

File details

Details for the file spatialiteintrospect-1.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for spatialiteintrospect-1.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 be4bcea3b00a1a1f73b74fefb317b52ef14f566ecb5799c7ec53e48549685216
MD5 2a84ef86a88422f8c2b3e20d03480ac3
BLAKE2b-256 78372d8d865eaae38305774e08c7b88f66e83b96f776acc546b5eb40cfe0df56

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.2 This release

2 files

1.1

2 files

1.0

2 files

0.3.1

1 file

0.3

2 files

0.2

1 file

0.1

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page