Async wrapper for Spark REST API
Project description
SPARK-REST-API
Async wrapper for Spark REST API. See more in documentation
INSTALL
pip install spark-rest-api
USAGE
import asyncio
import io
import zipfile
import aiohttp
import pandas as pd
from spark_rest_api import SparkRestApi
sra = SparkRestApi(spark_host="https://<host>:<port>")
sra.show_templates()
async def main(sra):
base_app_id = "application_XXXXXXXXXXXXX_XXXXXX"
async with aiohttp.ClientSession() as session:
resp = (
await sra.execute(
session=session,
url=sra.render_url(template_id=0)
)
)
assert resp.status == 200
df = resp.to_df()
attempts = df[df["id"] == base_app_id].attempts.tolist()
if attempts:
urls = map(
lambda x: sra.render_url(3, app_id=f"{base_app_id}/{x['attemptId']}"),
attempts[0]
)
df_result = pd.concat(
map(
lambda x: x.to_df(),
(
await asyncio.gather(*(sra.execute(session, url) for url in urls))
)
)
)
print(df_result)
log_data = await sra.execute(session, sra.render_url(template_id=13, base_app_id=base_app_id))
with zipfile.ZipFile(io.BytesIO(log_data.raw), "r") as zip_file:
for f in zip_file.infolist():
print(zip_file.read(f).decode())
loop = asyncio.get_event_loop()
loop.run_until_complete(main(sra))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
spark-rest-api-0.0.0.tar.gz
(9.9 kB
view details)
Built Distribution
File details
Details for the file spark-rest-api-0.0.0.tar.gz
.
File metadata
- Download URL: spark-rest-api-0.0.0.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e0e3367390aba4050a067903dbe41b654a6856eaf782dd68bb7ddc12781da6c |
|
MD5 | ae617e16e643c3b971bca84425134941 |
|
BLAKE2b-256 | f6e4dbd44f19dc7fc134132b3fa88b0806afcad341dfb57bf5451a2fe4110cdf |
File details
Details for the file spark_rest_api-0.0.0-py3-none-any.whl
.
File metadata
- Download URL: spark_rest_api-0.0.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c138d8cbfa71e02f6c67d8baa18cc8eec11aa29969c1936dc7cd7fd1e232f57 |
|
MD5 | efcf476c1bebcd1e37a8e42e088f6323 |
|
BLAKE2b-256 | 269a5cc0901193c645e482efd89687d183deac5cad1ada7360ab738253646e07 |