Azure blob storage support for polars (#17116)

## Release notes summary - What our users need to know

Introduces Azure support to the polars plugin. 

The following environment variables will are supported:
- AZURE_STORAGE_ACCOUNT_NAME: storage account name
- AZURE_STORAGE_ACCOUNT_KEY: storage account master key
- AZURE_STORAGE_ACCESS_KEY: alias for AZURE_STORAGE_ACCOUNT_KEY
- AZURE_STORAGE_CLIENT_ID: client id for service principal authorization
- AZURE_STORAGE_CLIENT_SECRET: client secret for service principal
authorization
- AZURE_STORAGE_TENANT_ID: tenant id used in oauth flows

Example Usage:
```nu
$env.AZURE_STORAGE_ACCOUNT_KEY = "<your access key value>"
$env.AZURE_STORAGE_ACCOUNT_NAME = "<your account name>"
ps | polars into-df | polars save azure://<your account name>/ps.parquet
polars open azure://<your account name>/ps.parquet | polars first 5 | polars collect
```

Co-authored-by: Jack Wright <jack.wright@nike.com>
This commit is contained in:
Jack Wright
2025-12-08 10:00:40 -08:00
committed by GitHub
co-authored by Jack Wright
parent 7f032cc748
commit 3d62b8ecba
4 changed files with 54 additions and 16 deletions
Generated
+2
View File
@@ -5000,6 +5000,7 @@ dependencies = [
"futures",
"http 1.3.1",
"http-body-util",
"httparse",
"humantime",
"hyper 1.5.1",
"itertools 0.14.0",
@@ -5010,6 +5011,7 @@ dependencies = [
"rand 0.9.0",
"reqwest",
"ring",
"rustls-pemfile 2.2.0",
"serde",
"serde_json",
"serde_urlencoded",
+2 -2
View File
@@ -33,7 +33,7 @@ indexmap = { version = "2.11" }
num = { version = "0.4" }
serde = { version = "1.0", features = ["derive"] }
sqlparser = { version = "=0.53.0" }
polars-io = { version = "=0.52.0", features = ["avro", "cloud", "aws"] }
polars-io = { version = "=0.52.0", features = ["avro", "cloud", "aws", "azure", "gcp"] }
polars-arrow = { version = "=0.52.0" }
polars-ops = { version = "=0.52.0", features = ["pivot", "cutqcut"] }
polars-plan = { version = "=0.52.0", features = ["regex"] }
@@ -53,7 +53,7 @@ hashbrown = { version = "0.16", features = ["rayon", "serde"] }
aws-config = { version = "1.5", features = ["sso"] }
aws-credential-types = "1.2"
tokio = { version = "1.45", features = ["full"] }
object_store = { version = "0.12", features = ["aws"], default-features = false }
object_store = { version = "0.12", features = ["aws", "azure", "gcp"], default-features = false }
url.workspace = true
[dependencies.polars]
@@ -0,0 +1,42 @@
use object_store::azure::MicrosoftAzureBuilder;
use polars_io::cloud::{AzureConfigKey, CloudOptions};
struct AzureOptionsBuilder {
builder: MicrosoftAzureBuilder,
}
impl AzureOptionsBuilder {
fn new() -> Self {
Self {
builder: MicrosoftAzureBuilder::new(),
}
}
fn get_config_value(&self, key: AzureConfigKey) -> Option<(AzureConfigKey, String)> {
self.builder.get_config_value(&key).map(|v| (key, v))
}
}
pub(crate) fn build_cloud_options() -> Result<CloudOptions, nu_protocol::ShellError> {
let builder = AzureOptionsBuilder::new();
// Variables extracted from environment:
// * AZURE_STORAGE_ACCOUNT_NAME: storage account name
// * AZURE_STORAGE_ACCOUNT_KEY: storage account master key
// * AZURE_STORAGE_ACCESS_KEY: alias for AZURE_STORAGE_ACCOUNT_KEY
// * AZURE_STORAGE_CLIENT_ID -> client id for service principal authorization
// * AZURE_STORAGE_CLIENT_SECRET -> client secret for service principal authorization
// * AZURE_STORAGE_TENANT_ID -> tenant id used in oauth flows
let configs = vec![
AzureConfigKey::AccountName,
AzureConfigKey::AccessKey,
AzureConfigKey::AccessKey,
AzureConfigKey::ClientId,
AzureConfigKey::ClientSecret,
AzureConfigKey::AuthorityId,
]
.into_iter()
.filter_map(|key| builder.get_config_value(key))
.collect::<Vec<(AzureConfigKey, String)>>();
Ok(CloudOptions::default().with_azure(configs))
}
+8 -14
View File
@@ -1,29 +1,23 @@
use nu_protocol::ShellError;
use polars::prelude::PlPath;
use polars_io::cloud::CloudOptions;
use polars_utils::plpath::CloudScheme;
use polars_io::cloud::{CloudOptions, CloudType};
use crate::PolarsPlugin;
mod aws;
enum CloudType {
Aws,
}
fn determine_cloud_type(plpath: &PlPath) -> Option<CloudType> {
match plpath.cloud_scheme() {
Some(CloudScheme::S3) | Some(CloudScheme::S3a) => Some(CloudType::Aws),
_ => None,
}
}
mod azure;
pub(crate) fn build_cloud_options(
plugin: &PolarsPlugin,
path: &PlPath,
) -> Result<Option<CloudOptions>, ShellError> {
match determine_cloud_type(path) {
match path
.cloud_scheme()
.map(|ref scheme| CloudType::from_cloud_scheme(scheme))
{
Some(CloudType::Aws) => aws::build_cloud_options(plugin).map(Some),
Some(CloudType::Azure) => azure::build_cloud_options().map(Some),
_ => Ok(None),
}
}