Skip to main content

Skeem


ci-tests Test suite code coverage license pypi-downloads python-versions status pypi-version

About

Skeem infers SQL DDL statements from tabular data.

Skeem is, amongst others, based on the excellent ddlgenerator, frictionless, fsspec, pandas, ScipPy, SQLAlchemy and xarray packages, and can be used both as a standalone program, and as a library.

Supported input data:

Supported input sources:

Please note that Skeem is beta-quality software, and a work in progress. Contributions of all kinds are very welcome, in order to make it more solid. Breaking changes should be expected until a 1.0 release, so version pinning is recommended, especially when you use it as a library.

Synopsis

skeem infer-ddl --dialect=postgresql data.ndjson
CREATE TABLE "data" (
    "id" SERIAL NOT NULL,
    "name" TEXT NOT NULL,
    "date" TIMESTAMP WITHOUT TIME ZONE,
    "fruits" TEXT NOT NULL,
    "price" DECIMAL(2, 2) NOT NULL,
    PRIMARY KEY ("id")
);

Quickstart

If you are in a hurry, and want to run Skeem without any installation, just use the OCI image on Podman or Docker.

docker run --rm ghcr.io/daq-tools/skeem-standard \
    skeem infer-ddl --dialect=postgresql \
    https://github.com/daq-tools/skeem/raw/main/tests/testdata/basic.ndjson

Setup

Install Skeem from PyPI.

pip install skeem

Install Skeem with support for additional data formats like NetCDF.

pip install 'skeem[full]'

Usage

This section outlines some example invocations of Skeem, both on the command line, and per library use. Other than the resources available from the web, testing data can be acquired from the repository’s testdata folder.

Command line use

Help

skeem info
skeem --help
skeem infer-ddl --help

Read from files

# NDJSON, Parquet, and InfluxDB line protocol (ILP) formats.
skeem infer-ddl --dialect=postgresql data.ndjson
skeem infer-ddl --dialect=postgresql data.parquet
skeem infer-ddl --dialect=postgresql data.lp

# CSV, JSON, ODS, and XLSX formats.
skeem infer-ddl --dialect=postgresql data.csv
skeem infer-ddl --dialect=postgresql data.json
skeem infer-ddl --dialect=postgresql data.ods
skeem infer-ddl --dialect=postgresql data.xlsx
skeem infer-ddl --dialect=postgresql data.xlsx --address="Sheet2"

Read from URLs

# CSV, NDJSON, XLSX
skeem infer-ddl --dialect=postgresql https://github.com/daq-tools/skeem/raw/main/tests/testdata/basic.csv
skeem infer-ddl --dialect=postgresql https://github.com/daq-tools/skeem/raw/main/tests/testdata/basic.ndjson
skeem infer-ddl --dialect=postgresql https://github.com/daq-tools/skeem/raw/main/tests/testdata/basic.xlsx --address="Sheet2"

# Google Sheets: Address first sheet, and specific sheet of workbook.
skeem infer-ddl --dialect=postgresql --table-name=foo https://docs.google.com/spreadsheets/d/1ExyrawjlyksbC6DOM6nLolJDbU8qiRrrhxSuxf5ScB0/view
skeem infer-ddl --dialect=postgresql --table-name=foo https://docs.google.com/spreadsheets/d/1ExyrawjlyksbC6DOM6nLolJDbU8qiRrrhxSuxf5ScB0/view#gid=883324548

# InfluxDB line protocol (ILP)
skeem infer-ddl --dialect=postgresql https://github.com/influxdata/influxdb2-sample-data/raw/master/air-sensor-data/air-sensor-data.lp

# Compressed files in gzip format
skeem --verbose infer-ddl --dialect=crate --content-type=ndjson https://s3.amazonaws.com/crate.sampledata/nyc.yellowcab/yc.2019.07.gz

# CSV on S3
skeem --verbose infer-ddl --dialect=postgresql s3://noaa-ghcn-pds/csv/by_year/2022.csv

# CSV on Google Cloud Storage
skeem --verbose infer-ddl --dialect=postgresql gs://tinybird-assets/datasets/nations.csv
skeem --verbose infer-ddl --dialect=postgresql gs://tinybird-assets/datasets/medals1.csv

# CSV on GitHub
skeem --verbose infer-ddl --dialect=postgresql github://daq-tools:skeem@/tests/testdata/basic.csv

# GRIB2, NetCDF
skeem infer-ddl --dialect=postgresql https://github.com/earthobservations/testdata/raw/main/opendata.dwd.de/weather/nwp/icon/grib/18/t/icon-global_regular-lat-lon_air-temperature_level-90.grib2
skeem infer-ddl --dialect=postgresql https://www.unidata.ucar.edu/software/netcdf/examples/sresa1b_ncar_ccsm3-example.nc
skeem infer-ddl --dialect=postgresql https://www.unidata.ucar.edu/software/netcdf/examples/WMI_Lear.nc

OCI

OCI images are available on the GitHub Container Registry (GHCR). In order to run them on Podman or Docker, invoke:

docker run --rm ghcr.io/daq-tools/skeem-standard \
    skeem infer-ddl --dialect=postgresql \
    https://github.com/daq-tools/skeem/raw/main/tests/testdata/basic.csv

If you want to work with files on your filesystem, you will need to either mount the working directory into the container using the --volume option, or use the --interactive option to consume STDIN, like:

docker run --rm --volume=$(pwd):/data ghcr.io/daq-tools/skeem-standard \
    skeem infer-ddl --dialect=postgresql /data/basic.ndjson

docker run --rm --interactive ghcr.io/daq-tools/skeem-standard \
    skeem infer-ddl --dialect=postgresql --content-type=ndjson - < basic.ndjson

In order to always run the latest nightly development version, and to use a shortcut for that, this section outlines how to use an alias for skeem, and a variable for storing the input URL. It may be useful to save a few keystrokes on subsequent invocations.

docker pull ghcr.io/daq-tools/skeem-standard:nightly
alias skeem="docker run --rm --interactive ghcr.io/daq-tools/skeem-standard:nightly skeem"
URL=https://github.com/daq-tools/skeem/raw/main/tests/testdata/basic.ndjson

skeem infer-ddl --dialect=postgresql $URL

More

Use a different backend (default: ddlgen):

skeem infer-ddl --dialect=postgresql --backend=frictionless data.ndjson

Reading data from STDIN needs to obtain both the table name and content type separately:

skeem infer-ddl --dialect=crate --table-name=foo --content-type=ndjson - < data.ndjson

Reading data from STDIN also works like this, if you prefer to use pipes:

cat data.ndjson | skeem infer-ddl --dialect=crate --table-name=foo --content-type=ndjson -

Library use

import io
from skeem.core import SchemaGenerator
from skeem.model import Resource, SqlTarget

INDATA = io.StringIO(
    """
    {"id":1,"name":"foo","date":"2014-10-31 09:22:56","fruits":"apple,banana","price":0.42}
    {"id":2,"name":"bar","date":null,"fruits":"pear","price":0.84}
    """
)

sg = SchemaGenerator(
    resource=Resource(data=INDATA, content_type="ndjson"),
    target=SqlTarget(dialect="crate", table_name="testdrive"),
)

print(sg.to_sql_ddl().pretty)
CREATE TABLE "testdrive" (
    "id" INT NOT NULL,
    "name" STRING NOT NULL,
    "date" TIMESTAMP,
    "fruits" STRING NOT NULL,
    "price" DOUBLE NOT NULL,
    PRIMARY KEY ("id")
);

Development

For installing the project from source, please follow the development documentation.

Project information

Credits

Prior art

We are maintaining a list of other projects with the same or similar goals like Skeem.

Etymology

The program was about to be called Eskema, but it turned out that there is already another Eskema out there. So, it has been renamed to Skeem, which is Estonian, and means “schema”, “outline”, or “(to) plan”.

Metadata

Release files for skeem 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for skeem 0.2.0
File Size Uploaded Provenance Actions
skeem-0.2.0.tar.gz 56.0 kB Without provenance Details for skeem-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for skeem 0.2.0
File Interpreter ABI Platform Actions
skeem-0.2.0-py3-none-any.whl Python 3 none any Details for skeem-0.2.0-py3-none-any.whl

Total release size: 98.5 kB

Release files / skeem-0.2.0.tar.gz

Download URL skeem-0.2.0.tar.gz
Size 56.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9d464c76ff33f3407607f2913a6ee3257ae1ea7c16c36a9d2f0cc7d244fdb42c
BLAKE2b-256 checksum
How to use checksums
b19c4551ab42e22dd1ea13d87af259df177773eeae41bb89c344b783cba7466a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / skeem-0.2.0-py3-none-any.whl

Download URL skeem-0.2.0-py3-none-any.whl
Size 42.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
383bf57230175099dea37a8181e6ea7c6e154a12c168f14351eb640ceedc5a4d
BLAKE2b-256 checksum
How to use checksums
b2628526c8f73fc7e85c387eaff40ce55774bca9f4591999af764c1de3eeb328
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for skeem 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page