Python client library for Altertable
Project description
altertable-flightsql
Python client library for Altertable.
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/
The mock service container is forced to run as linux/amd64 to keep parity with CI
and to work reliably on Apple Silicon machines (Docker Desktop will handle
emulation automatically).
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!
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes with tests
- If you modified
.protofiles, runmake gen - Run code quality checks:
make lintandpytest - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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 genand commit generated files when modifying.protofiles - Run
make lintbefore 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file altertable_flightsql-0.2.2.tar.gz.
File metadata
- Download URL: altertable_flightsql-0.2.2.tar.gz
- Upload date:
- Size: 44.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e36e2c54f1d7abbc34f746e3e9803f4c00830b0d1b366c3eca7c429037210e36
|
|
| MD5 |
828821bff5a71e0149ac8bad52eae1c7
|
|
| BLAKE2b-256 |
16dfba7f2edc2a6536e0809e2c15853414d1cf18ba396736066e085ac19adccb
|
Provenance
The following attestation bundles were made for altertable_flightsql-0.2.2.tar.gz:
Publisher:
publish.yml on altertable-ai/altertable-flightsql-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
altertable_flightsql-0.2.2.tar.gz -
Subject digest:
e36e2c54f1d7abbc34f746e3e9803f4c00830b0d1b366c3eca7c429037210e36 - Sigstore transparency entry: 1251600257
- Sigstore integration time:
-
Permalink:
altertable-ai/altertable-flightsql-python@0b46662aaba031c53c769cbcc497f6ceacfe3cb6 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/altertable-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0b46662aaba031c53c769cbcc497f6ceacfe3cb6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file altertable_flightsql-0.2.2-py3-none-any.whl.
File metadata
- Download URL: altertable_flightsql-0.2.2-py3-none-any.whl
- Upload date:
- Size: 24.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef7162f6a118bfdd48106acb2a31f571af11e633e99b7f718113818baeff1891
|
|
| MD5 |
c75ad2f44b2f72dd3ebbdb793a6eb280
|
|
| BLAKE2b-256 |
614f2d38597d37e4744b07dd809c816f181f40b89e2f0512ca98a82a0827f713
|
Provenance
The following attestation bundles were made for altertable_flightsql-0.2.2-py3-none-any.whl:
Publisher:
publish.yml on altertable-ai/altertable-flightsql-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
altertable_flightsql-0.2.2-py3-none-any.whl -
Subject digest:
ef7162f6a118bfdd48106acb2a31f571af11e633e99b7f718113818baeff1891 - Sigstore transparency entry: 1251600282
- Sigstore integration time:
-
Permalink:
altertable-ai/altertable-flightsql-python@0b46662aaba031c53c769cbcc497f6ceacfe3cb6 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/altertable-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0b46662aaba031c53c769cbcc497f6ceacfe3cb6 -
Trigger Event:
release
-
Statement type: