-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generic pyo3 integration for object-store (#229)
* wip pyo3-object-store * wip * fix import * Implement ObjectStore creation APIs * rename * Cleanup * Add local and in-memory object-store * Fix module add * Cleaner store errors * remove test_s3 * remove test_fsspec
- Loading branch information
1 parent
2d3b583
commit 6d513ea
Showing
27 changed files
with
2,333 additions
and
29 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from ._io import * | ||
from ._io import ___version | ||
from ._io import ___version, store | ||
|
||
__version__: str = ___version() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# TODO: move this to a standalone package/docs website that can be shared across | ||
# multiple python packages. | ||
|
||
from __future__ import annotations | ||
|
||
from datetime import timedelta | ||
from typing import Dict, TypedDict | ||
|
||
import boto3 | ||
import botocore | ||
import botocore.session | ||
|
||
class BackoffConfig(TypedDict): | ||
init_backoff: timedelta | ||
max_backoff: timedelta | ||
base: int | float | ||
|
||
class RetryConfig(TypedDict): | ||
backoff: BackoffConfig | ||
max_retries: int | ||
retry_timeout: timedelta | ||
|
||
class AzureStore: | ||
@classmethod | ||
def from_env( | ||
cls, | ||
container: str, | ||
*, | ||
config: Dict[str, str] | None = None, | ||
client_options: Dict[str, str] | None = None, | ||
retry_config: RetryConfig | None = None, | ||
) -> S3Store: ... | ||
@classmethod | ||
def from_url( | ||
cls, | ||
url: str, | ||
*, | ||
config: Dict[str, str] | None = None, | ||
client_options: Dict[str, str] | None = None, | ||
retry_config: RetryConfig | None = None, | ||
) -> S3Store: ... | ||
|
||
class GCSStore: | ||
@classmethod | ||
def from_env( | ||
cls, | ||
bucket: str, | ||
*, | ||
config: Dict[str, str] | None = None, | ||
client_options: Dict[str, str] | None = None, | ||
retry_config: RetryConfig | None = None, | ||
) -> S3Store: ... | ||
@classmethod | ||
def from_url( | ||
cls, | ||
url: str, | ||
*, | ||
config: Dict[str, str] | None = None, | ||
client_options: Dict[str, str] | None = None, | ||
retry_config: RetryConfig | None = None, | ||
) -> S3Store: ... | ||
|
||
class HTTPStore: | ||
@classmethod | ||
def from_url( | ||
cls, | ||
url: str, | ||
*, | ||
client_options: Dict[str, str] | None = None, | ||
retry_config: RetryConfig | None = None, | ||
) -> S3Store: ... | ||
|
||
class S3Store: | ||
@classmethod | ||
def from_env( | ||
cls, | ||
bucket: str, | ||
*, | ||
config: Dict[str, str] | None = None, | ||
client_options: Dict[str, str] | None = None, | ||
retry_config: RetryConfig | None = None, | ||
) -> S3Store: ... | ||
@classmethod | ||
def from_session( | ||
cls, | ||
session: boto3.Session | botocore.session.Session, | ||
bucket: str, | ||
*, | ||
config: Dict[str, str] | None = None, | ||
client_options: Dict[str, str] | None = None, | ||
retry_config: RetryConfig | None = None, | ||
) -> S3Store: ... | ||
@classmethod | ||
def from_url( | ||
cls, | ||
url: str, | ||
*, | ||
config: Dict[str, str] | None = None, | ||
client_options: Dict[str, str] | None = None, | ||
retry_config: RetryConfig | None = None, | ||
) -> S3Store: ... | ||
|
||
class LocalStore: | ||
""" | ||
Local filesystem storage providing an ObjectStore interface to files on local disk. | ||
Can optionally be created with a directory prefix. | ||
""" | ||
def __init__(self, prefix: str | None = None) -> None: ... | ||
|
||
class MemoryStore: | ||
"""A fully in-memory implementation of ObjectStore.""" | ||
def __init__(self) -> None: ... | ||
|
||
ObjectStore = AzureStore | GCSStore | HTTPStore | S3Store | LocalStore | MemoryStore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# TODO: move to reusable types package | ||
from ._pyo3_object_store import AzureStore as AzureStore | ||
from ._pyo3_object_store import GCSStore as GCSStore | ||
from ._pyo3_object_store import HTTPStore as HTTPStore | ||
from ._pyo3_object_store import LocalStore as LocalStore | ||
from ._pyo3_object_store import MemoryStore as MemoryStore | ||
from ._pyo3_object_store import S3Store as S3Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//! Contains the [`Arro3IoError`], the Error returned by most fallible functions in this crate. | ||
use pyo3::exceptions::{PyException, PyValueError}; | ||
use pyo3::prelude::*; | ||
use pyo3::DowncastError; | ||
use thiserror::Error; | ||
|
||
/// The Error variants returned by this crate. | ||
#[derive(Error, Debug)] | ||
#[non_exhaustive] | ||
pub enum Arro3IoError { | ||
/// A wrapped [arrow::error::ArrowError] | ||
#[error(transparent)] | ||
ArrowError(#[from] arrow::error::ArrowError), | ||
|
||
/// A wrapped [object_store::Error] | ||
#[error(transparent)] | ||
ObjectStoreError(#[from] object_store::Error), | ||
|
||
/// A wrapped [parquet::errors::ParquetError] | ||
#[error(transparent)] | ||
ParquetError(#[from] parquet::errors::ParquetError), | ||
|
||
/// A wrapped [PyErr] | ||
#[error(transparent)] | ||
PyErr(#[from] PyErr), | ||
} | ||
|
||
impl From<Arro3IoError> for PyErr { | ||
fn from(error: Arro3IoError) -> Self { | ||
match error { | ||
Arro3IoError::PyErr(err) => err, | ||
Arro3IoError::ArrowError(err) => PyException::new_err(err.to_string()), | ||
Arro3IoError::ObjectStoreError(err) => PyException::new_err(err.to_string()), | ||
Arro3IoError::ParquetError(err) => PyException::new_err(err.to_string()), | ||
} | ||
} | ||
} | ||
|
||
impl<'a, 'py> From<DowncastError<'a, 'py>> for Arro3IoError { | ||
fn from(other: DowncastError<'a, 'py>) -> Self { | ||
Self::PyErr(PyValueError::new_err(format!( | ||
"Could not downcast: {}", | ||
other | ||
))) | ||
} | ||
} | ||
|
||
/// A type wrapper around `Result<T, Arro3IoError>`. | ||
pub type Arro3IoResult<T> = Result<T, Arro3IoError>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[package] | ||
name = "pyo3-object_store" | ||
version = "0.1.0" | ||
authors = { workspace = true } | ||
edition = { workspace = true } | ||
description = "object_store integration for pyo3." | ||
readme = "README.md" | ||
repository = { workspace = true } | ||
license = { workspace = true } | ||
keywords = { workspace = true } | ||
categories = { workspace = true } | ||
rust-version = { workspace = true } | ||
|
||
[dependencies] | ||
futures = "0.3.30" | ||
object_store = { workspace = true, features = ["aws", "azure", "gcp", "http"] } | ||
pyo3 = { workspace = true, features = ["chrono", "indexmap"] } | ||
pyo3-async-runtimes = { git = "https://github.com/PyO3/pyo3-async-runtimes", features = [ | ||
"tokio-runtime", | ||
] } | ||
thiserror = { workspace = true } | ||
|
||
[dev-dependencies] | ||
arrow-select = { workspace = true } | ||
|
||
[lib] | ||
crate-type = ["rlib"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# pyo3-object_store | ||
|
||
Use `object-store` in your pyo3-based libraries. |
Oops, something went wrong.