Skip to main content

Async wrapper for Spark REST API

Project description

SRA

Version License Python Status Format Wheel Build Coverage Downloads


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


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)

Uploaded Source

Built Distribution

spark_rest_api-0.0.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

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

Hashes for spark-rest-api-0.0.0.tar.gz
Algorithm Hash digest
SHA256 9e0e3367390aba4050a067903dbe41b654a6856eaf782dd68bb7ddc12781da6c
MD5 ae617e16e643c3b971bca84425134941
BLAKE2b-256 f6e4dbd44f19dc7fc134132b3fa88b0806afcad341dfb57bf5451a2fe4110cdf

See more details on using hashes here.

File details

Details for the file spark_rest_api-0.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for spark_rest_api-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c138d8cbfa71e02f6c67d8baa18cc8eec11aa29969c1936dc7cd7fd1e232f57
MD5 efcf476c1bebcd1e37a8e42e088f6323
BLAKE2b-256 269a5cc0901193c645e482efd89687d183deac5cad1ada7360ab738253646e07

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page