Skip to main content

Lightweight online feature store backed by a SQL database (currently PostgreSQL) with a pandas API: automatic table creation, column migration, upserts, and chunked reads.

Project description

sql-feature-store

PyPI CI codecov License: MIT Python

Lightweight online feature store backed by a SQL database, with a pandas API. Currently implemented for PostgreSQL; designed so other SQL backends (e.g. MySQL) can be added later.

What it does

  • Parses a DataFrame into appropriate column types
  • Creates the destination table if it does not exist
  • Migrates the table by adding new columns when the DataFrame has extra ones
  • Supports write modes: fail, replace, append
  • Supports index creation and ON CONFLICT DO UPDATE upserts
  • Reads via SQL (optionally in chunks)

Install

pip install sql-feature-store

Requires Python >=3.10,<3.14.

Quickstart

import pandas as pd
from sql_feature_store import FeatureStore, PostgresConfig

config = PostgresConfig(
    host="localhost",
    port=5432,
    user="postgres",
    password="postgres",
    dbname="postgres",
)
store = FeatureStore(config=config)

df = pd.DataFrame({"user_id": [1, 2, 3], "country": ["US", "UK", None]})
store.write("users", data_frame=df, write_option="replace")

result = store.read("select * from predictions.users")
# >>> result
#    user_id country
# 0        1      US
# 1        2      UK
# 2        3    None

Credentials are passed in directly — sourcing them (env vars, AWS Secrets Manager, Vault, etc.) is the caller's responsibility.

Testing your own code

sql-feature-store ships a pytest plugin so your tests can hit a real PostgreSQL without wiring up fixtures from scratch. Install the testing extra:

pip install sql-feature-store[testing]

Three fixtures are auto-discovered:

  • sql_feature_store_postgres_proc — a Postgres process (spawned via pytest-postgresql, or an external DB when SFS_POSTGRES_HOST is set).
  • sql_feature_store_config — a PostgresConfig with a fresh random write_schema per test, dropped on teardown.
  • sql_feature_store_fixture — a ready FeatureStore pointed at that schema.
import pandas as pd

def test_round_trip(sql_feature_store_fixture, sql_feature_store_config):
    store = sql_feature_store_fixture
    schema = sql_feature_store_config.write_schema

    store.write("users", data_frame=pd.DataFrame({"user_id": [1, 2, 3]}))
    result = store.read(f"select * from {schema}.users")
    assert len(result) == 3

See docs/usage.md for the full fixture reference and the external-database env vars.

Documentation

  • docs/usage.md — full API reference: chunked reads, write modes, indexes, ON CONFLICT DO UPDATE upserts, automatic column migration, and the pytest fixture reference.
  • docs/roadmap.md — what's coming next, organised by target version (online feature store → multi-dialect → offline → 1.0).

Contributing

Bug reports, feature requests, and pull requests are welcome. See CONTRIBUTING.md for development setup and the PR workflow, and CHANGELOG.md for release notes.

Layout

sql-feature-store/
├── pyproject.toml
├── .pre-commit-config.yaml
├── docs/
│   ├── usage.md
│   └── roadmap.md
├── src/sql_feature_store/
│   ├── __init__.py
│   ├── config.py              # PostgresConfig dataclass
│   ├── store.py               # FeatureStore
│   └── testing/               # pytest plugin shipped as [testing] extra
│       └── plugin.py          # fixtures: _postgres_proc, _config, _fixture
└── tests/
    └── integration/           # one test file per feature area

License

Released under the MIT License.

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

sql_feature_store-0.2.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

sql_feature_store-0.2.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file sql_feature_store-0.2.0.tar.gz.

File metadata

  • Download URL: sql_feature_store-0.2.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sql_feature_store-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b1f8a102561431b9773c3f9134b7d4e870fd5c4b6788a673e1d9fc2c84a8b034
MD5 23659861bd4bef4dfe4dc4c02aa1de9a
BLAKE2b-256 91fd7fffbdfcc7cccef31ef8cf73aa8ae4d63ed32d4dad982c994aee51a4bbfe

See more details on using hashes here.

Provenance

The following attestation bundles were made for sql_feature_store-0.2.0.tar.gz:

Publisher: release.yml on mshka/sql-feature-store

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sql_feature_store-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sql_feature_store-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e3779cf744aea5f9a6ffa47dd1f8e1dba4c502d6d848b3cc846db3c251f01c52
MD5 5a3b37ed5abe6cb4b1bd0406b70b1cc9
BLAKE2b-256 727c30524eab63f3e8b8ba22307a3cfa778fedfb1c20add1bfd62833cc111af8

See more details on using hashes here.

Provenance

The following attestation bundles were made for sql_feature_store-0.2.0-py3-none-any.whl:

Publisher: release.yml on mshka/sql-feature-store

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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