Skip to main content

Python client library for Altertable

Project description

altertable-flightsql

Python client library for Altertable.

License Python

Installation

pip install altertable-flightsql

Quick Start

from altertable_flightsql import Client

# Connect to Altertable
with Client(username="your_username", password="your_password") as client:
    # Execute a query
    reader = client.query("SELECT * FROM users WHERE age > 18")

    # Process results
    for batch in reader:
        df = batch.data.to_pandas()
        print(df)

Connect to specific catalog/schema

# Connect to custom host/port
client = Client(
    username="admin",
    password="secret",
    catalog="my_catalog",
    schema="my_schema"
)

Queries and Updates

# Execute SELECT query
reader = client.query("SELECT * FROM users")
for batch in reader:
    print(batch.data.to_pandas())

# Execute INSERT/UPDATE/DELETE
rows_affected = client.execute("INSERT INTO users (name) VALUES ('Alice')")
print(f"Affected {rows_affected} rows")

Prepared Statements

# Prepare once, execute multiple times
with client.prepare("SELECT * FROM users WHERE id = $id") as stmt:
    result = stmt.query(parameters={"id": 1}))
    for batch in result:
        print(batch.data.to_pandas())

Transactions

with client.begin_transaction():
    client.execute("INSERT INTO users ...")
    client.execute("UPDATE accounts ...")

Metadata Queries

# Get catalogs, schemas, tables
catalogs = client.get_catalogs()
schemas = client.get_schemas(catalog="my_db")
tables = client.get_tables(catalog="my_db", schema_pattern="public")

Development

Setup

# Clone repository
git clone https://github.com/altertable-ai/altertable-flightsql-python.git
cd altertable-flightsql-python

# Install with dev dependencies
pip install -e ".[dev]"

Running Tests

pytest                           # Run tests

Code Quality

make lint                        # Run all linters (isort, black, ruff, mypy)

Compiling Protocol Definitions

If you modify the .proto files, you need to recompile them:

make gen                         # Compile protobuf definitions

Important: The CI will fail if generated files are out of sync with the proto definitions. Always run make gen and commit the generated files after modifying .proto files.

Examples

See the examples/ directory for complete examples:

# High-level client examples
python examples/client_usage.py

Testing

This package includes comprehensive integration tests that validate functionality against a real Altertable service.

Running Tests

Using testcontainers (local development):

# Install development dependencies
pip install -e ".[dev]"

# Run all tests
# Having the ghcr.io/altertable-ai/altertable-mock docker image locally will speed things up.
pytest tests/

Using an existing service (CI/production):

# Set environment variables
export ALTERTABLE_HOST=localhost
export ALTERTABLE_PORT=15002
export ALTERTABLE_USERNAME=altertable-test
export ALTERTABLE_PASSWORD=lk_test

# Run tests
pytest tests/

The test suite automatically detects whether to use testcontainers or an existing service based on environment variables. If ALTERTABLE_HOST and ALTERTABLE_PORT are set, tests will connect to that service. Otherwise, they'll start a Docker container with altertable.ai/altertable-mock.

Contributing

Contributions are welcome!

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes with tests
  4. If you modified .proto files, run make gen
  5. Run code quality checks: make lint and pytest
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

Development Guidelines

  • Follow PEP 8 style (enforced by Black, line length: 100)
  • Add tests for new features
  • Include docstrings (Google style)
  • Update documentation as needed
  • Run make gen and commit generated files when modifying .proto files
  • Run make lint before committing to ensure code quality

Architecture

altertable-flightsql/
├── src/altertable_flightsql/
│   ├── __init__.py              # Package exports
│   ├── client.py                # Main Client class
│   └── generated/               # Internal protocol definitions
├── tests/                       # Test suite
└── examples/                    # Usage examples

License

MIT License - See LICENSE file for details.

Built on Apache Arrow Flight SQL protocol.

Resources

Acknowledgments

Built on Apache Arrow Flight SQL protocol.

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

altertable_flightsql-0.2.1.tar.gz (43.5 kB view details)

Uploaded Source

Built Distribution

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

altertable_flightsql-0.2.1-py3-none-any.whl (23.9 kB view details)

Uploaded Python 3

File details

Details for the file altertable_flightsql-0.2.1.tar.gz.

File metadata

  • Download URL: altertable_flightsql-0.2.1.tar.gz
  • Upload date:
  • Size: 43.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for altertable_flightsql-0.2.1.tar.gz
Algorithm Hash digest
SHA256 1d27296bf41f7c3f8ef50388631ed7d3d0e8a765ab2e2ea58813ae90bd7c4ed3
MD5 1c04053a8fb0dd9801e8d6a56bb737f0
BLAKE2b-256 f525dde078e2e1b0b5230557daba7f7163b2e235abbdd5a54d18639adb284970

See more details on using hashes here.

Provenance

The following attestation bundles were made for altertable_flightsql-0.2.1.tar.gz:

Publisher: publish.yml on altertable-ai/altertable-flightsql-python

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

File details

Details for the file altertable_flightsql-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for altertable_flightsql-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ff97ce7963d090e513be9f4865f51bb9a6849bbed42ed9ffbe7bd61cbc857c72
MD5 1a0bfcbb655ca0612366936d76c73a8a
BLAKE2b-256 9521da22cc8335450cb38d7a63d51a36b83cf128435d64d7b825be547b5415f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for altertable_flightsql-0.2.1-py3-none-any.whl:

Publisher: publish.yml on altertable-ai/altertable-flightsql-python

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