Skip to main content

Snowflake backend implementation for rhosocial-activerecord, providing cloud data warehouse support with VARIANT, ARRAY, and time travel features.

Project description

rhosocial-activerecord-snowflake

Python Apache 2.0 License Powered by vistart

rhosocial ActiveRecord Logo

Snowflake Backend for rhosocial-activerecord

Cloud Data Warehouse Support · VARIANT & ARRAY Types · Time Travel Queries

Note: This is a backend implementation for rhosocial-activerecord. It cannot be used standalone.

Why This Backend?

1. Snowflake-Specific Optimizations

Feature This Backend Generic Solutions
VARIANT Type Native semi-structured data JSON serialize/deserialize
Time Travel AT/BEFORE point-in-time queries Manual snapshot management
ARRAY Type Native array operations Comma-separated strings
MERGE Native upsert with conditions Manual check-then-insert

2. True Sync-Async Parity

Same API surface for both sync and async operations:

# Sync
users = User.query().where(User.c.age >= 18).all()

# Async - just add await
users = await User.query().where(User.c.age >= 18).all()

3. Built for Cloud Data Warehouse

  • Warehouse-aware connection configuration
  • Schema and role support for multi-tenant environments
  • Time travel for point-in-time data access
  • VARIANT/ARRAY type adapters for semi-structured data

Quick Start

Installation

pip install rhosocial-activerecord-snowflake

Basic Usage

from rhosocial.activerecord.model import ActiveRecord
from rhosocial.activerecord.backend.impl.snowflake import SnowflakeBackend
from rhosocial.activerecord.backend.impl.snowflake.config import SnowflakeConnectionConfig
from typing import Optional

class User(ActiveRecord):
    __table_name__ = "users"
    id: Optional[int] = None
    name: str
    email: str

# Configure
config = SnowflakeConnectionConfig(
    account="your-account",
    warehouse="COMPUTE_WH",
    database="myapp",
    schema="public",
    username="user",
    password="password",
    role="SYSADMIN"
)
User.configure(config, SnowflakeBackend)

# Use
user = User(name="Alice", email="alice@example.com")
user.save()

Snowflake-Specific Features

VARIANT Type (Semi-Structured Data)

Native Snowflake VARIANT support for JSON-like data:

from rhosocial.activerecord.backend.impl.snowflake import SnowflakeVariantAdapter

# Store and query semi-structured data
settings = {"theme": "dark", "notifications": True}

Time Travel Queries

Access historical data using Snowflake's time travel capabilities:

# Query data as of a specific timestamp
results = User.query().where(User.c.age >= 18).all()

# Time travel with AT/BEFORE clauses (via raw SQL)

MERGE (Conditional Upsert)

Efficient conditional insert-or-update operations:

# Snowflake MERGE support for complex upsert scenarios

Requirements

  • Python: 3.8+ (including 3.14t free-threaded builds; 3.13t is NOT supported due to cffi dependency incompatibility)
  • Core: rhosocial-activerecord>=0.9.0
  • Driver: snowflake-connector-python>=3.0.0

Comparison with Other Backends

Feature Snowflake MySQL PostgreSQL SQLite
VARIANT/JSON ✅ VARIANT ✅ JSON ✅ JSONB ⚠️ JSON1
Arrays ✅ ARRAY ✅ Native
Time Travel ✅ Native
MERGE ✅ Native ✅ (PG 15+)
RETURNING
Cloud-Native

Testing

⚠️ CRITICAL: Tests MUST run serially. Do NOT use pytest -n auto or parallel execution.

# Run all tests
PYTHONPATH=src pytest tests/

# Run specific feature tests
PYTHONPATH=src pytest tests/rhosocial/activerecord_snowflake_test/feature/backend/

Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

License

Apache License 2.0 — Copyright © 2025 vistart


Built with ❤️ by the rhosocial team

GitHub · Documentation · PyPI

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

rhosocial_activerecord_snowflake-1.0.0.dev1.tar.gz (31.1 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file rhosocial_activerecord_snowflake-1.0.0.dev1.tar.gz.

File metadata

File hashes

Hashes for rhosocial_activerecord_snowflake-1.0.0.dev1.tar.gz
Algorithm Hash digest
SHA256 7a3f4770d1ac9c248aeb5b00ba081c3b75a631be01af5d37fef0a97f2a427edd
MD5 92e296683a06384c201a1a6d7808664d
BLAKE2b-256 91722a36636153b94200050f553826be4472d5e675d2b9d48a6d7f2c1a240f32

See more details on using hashes here.

Provenance

The following attestation bundles were made for rhosocial_activerecord_snowflake-1.0.0.dev1.tar.gz:

Publisher: publish.yml on rhosocial/python-activerecord-snowflake

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

File details

Details for the file rhosocial_activerecord_snowflake-1.0.0.dev1-py3-none-any.whl.

File metadata

File hashes

Hashes for rhosocial_activerecord_snowflake-1.0.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 7b53823ae67669c45bc01533af3a7def0e6f402b18ad955aa96f718fb9b6eeee
MD5 7d7facba64c08e154dca97e419a07b36
BLAKE2b-256 5cd1451da9d2a29a49472a377b1174cc53582de36b244acd354f7eea7ee9b597

See more details on using hashes here.

Provenance

The following attestation bundles were made for rhosocial_activerecord_snowflake-1.0.0.dev1-py3-none-any.whl:

Publisher: publish.yml on rhosocial/python-activerecord-snowflake

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