Skip to main content

Fetch and parse MSSQL schema metadata into structured Table objects

Project description

samla

Fetches and parses MSSQL schema metadata (tables, views, columns) into structured Python objects.

Install

pip install samla

Usage

From a database connection

Connects directly to MSSQL and fetches schema metadata:

import pyodbc
from samla import get_and_parse_tables, FilterGroup

filters = [
    FilterGroup(catalog_patterns=["NorthernVault"], schema_patterns=["Reporting"]),
]

conn = pyodbc.connect("<your connection string>")
tables = get_and_parse_tables(conn=conn, source_system="ACME", filters=filters)

The SQL query used to fetch metadata from INFORMATION_SCHEMA is available here.

From a CSV file

If you cannot connect to the database directly, load from a pre-exported CSV file instead:

from pathlib import Path
from samla import load_tables_from_file

tables = load_tables_from_file(path=Path("tables.csv"))

To produce the CSV, save the output from a database run:

from samla import save_tables_to_file

save_tables_to_file(tables=tables, path=Path("tables.csv"))

Or from the command line

python main.py                        # fetch from database
python main.py --file tables.csv      # load from CSV file

Filtering

FilterGroup filters tables by catalog, schema, and/or table name using regex patterns. Multiple patterns within a field are OR'd; multiple FilterGroups are also OR'd between each other.

filters = [
    FilterGroup(schema_patterns=["Sales", "Person"]),
    FilterGroup(catalog_patterns=["AdventureWorks"], table_patterns=["^Product"]),
]

Data model

Table

Field Type Description
source_system str Identifier for the source system
server_name str | None Hostname of the server
catalog str Database catalog name
schema str Schema name
table str Table or view name
table_type TableType TABLE or VIEW
columns list[SourceColumn] Column definitions

SourceColumn

Field Type Description
column str Column name
data_type str SQL data type
length str | None Character max length
nullable bool Whether the column is nullable
scale int | None Numeric scale
precision int | None Numeric precision
is_primary_key bool Whether the column is a primary key
source_type TableType TABLE or VIEW

Development

pip install -e ".[dev]"
pytest

Project details


Download files

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

Source Distribution

samla-0.1.3.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

samla-0.1.3-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file samla-0.1.3.tar.gz.

File metadata

  • Download URL: samla-0.1.3.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for samla-0.1.3.tar.gz
Algorithm Hash digest
SHA256 0be3adfbe2b62cce87b1eb7fe285a596a5bc70b46093b340afcad4f9124830c6
MD5 b3e4ae22f16575117a494e528f719159
BLAKE2b-256 4c0ceaecd40127a09352fe83f658808af69a3ca9a706a9ae20081607b0eaf336

See more details on using hashes here.

File details

Details for the file samla-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: samla-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for samla-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 11e30787ca10da23984fae70cbb8c988da3c0ee50dc2fa4dbd2bc8fa60598957
MD5 d86d4c14d078f398a937334d6fb1df8a
BLAKE2b-256 789c2b496a4aa06773e3b146532dadfe0470bbdf9fbf660092b24635e570c20d

See more details on using hashes here.

Supported by

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