Skip to main content

A Python library that provides unified utilities for working with local and

Project description

AltairAnt

A Python library providing unified utilities for working with local and cloud-based data, including DuckDB database wrappers, file system abstractions for Google Cloud Storage (GCS), and JSON to DataFrame loading with multiple schema handlers.

Features

  • DuckDB Integration: Simplified database operations with context-managed connections.
  • GCS File System: Seamless file access and synchronization between local and remote storage.
  • JSON to DataFrame Loader: Automatic conversion of various JSON formats to pandas DataFrames using extensible schema handlers.

Installation

Install from source or via pip:

pip install altairant

Usage

JSON to DataFrame Loader

from altairant.json_df_loader import JsonToDataFrameLoader

loader = JsonToDataFrameLoader()

# Example: List of dicts
data = [
    {"id": 1, "name": "Alice", "value": 3.14},
    {"id": 2, "name": "Bob", "value": 2.71}
]

df = loader.load(data)
print(df)

Supported JSON schemas include:

  • List of dictionaries
  • Columnar format (dict of lists)
  • Column-rows format (with metadata)
  • Nested data under a "data" key

DuckDB Wrapper

from altairant.gcs.duckstore import DuckDBStore

# One short execution
JSON_KEY = "path/to/gcp_key.json"
CREDS = service_account.Credentials.from_service_account_file(JSON_KEY)
URI = "gs://your-bucket-name/db.duckdb"

db = DuckDBCloud(self.URI, credentials=self.CREDS, read_only=False)
db.execute("CREATE TABLE IF NOT EXISTS test AS SELECT 1 AS id, 'foo' AS name")
results = db.execute("SELECT * FROM test")

# With session
with db.session() as conn:
    conn.execute("CREATE TABLE IF NOT EXISTS session_test AS SELECT 3 AS id, 'baz' AS name")
    conn.execute("INSERT INTO session_test VALUES (4, 'qux')")
    results = conn.execute("SELECT * FROM session_test").fetchall()

GCS File System

from google.oauth2 import service_account
from altairant.gcs.file_manager import GCSFileManager

JSON_KEY = "path/to/gcp_key.json"
CREDS = service_account.Credentials.from_service_account_file(JSON_KEY)

gcs_file_path = "gs://your-bucket-name/test_file_gcs.txt"
write_to_file_path = "gs://your-bucket-name/test_write_fileSystem.txt"

gcs_fs = GCSFileSystem(credentials=self.CREDS)
with gcs_fs.open(self.gcs_path, mode="r") as f:
    content = f.read()
    print(content)

test_content = "Hello, GCS! This is a test write."
    with gcs_fs.open(write_to_file_path, mode="w") as f:
        f.write(test_content)

Requirements

  • Python >= 3.8
  • pandas
  • duckdb
  • google-cloud-storage
  • gcsfs

License

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

altairant-1.1.2.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

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

altairant-1.1.2-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file altairant-1.1.2.tar.gz.

File metadata

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

File hashes

Hashes for altairant-1.1.2.tar.gz
Algorithm Hash digest
SHA256 6a19eb4504cab2d0b7d74a7917bf25cb8e1112534478dda9b1a659e1b51c8350
MD5 d586762af527cf829ff83f62aa86e412
BLAKE2b-256 82aedfd23fcea14059ffae32f810b3d91d3695e7c66c0570063420c7acbdf62d

See more details on using hashes here.

File details

Details for the file altairant-1.1.2-py3-none-any.whl.

File metadata

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

File hashes

Hashes for altairant-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1588b6c30129dd4996d8902ba9440894bb0c64a2d6bd18ab25a1b1beac610579
MD5 548a122e64a8b289f87aa0b6bde75a6b
BLAKE2b-256 43b81d2b43654bf20014aa00f282013195131e7aae9e771f11e1dadcc30fa356

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