Skip to main content

Apache Livy Client

Project description

livyc

Apache Livy Client

Install library

pip install livyc

Import library

from livyc import livyc

Setting livy configuration

data_livy = {
    "livy_server_url": "localhost",
    "port": "8998",
    "jars": ["org.postgresql:postgresql:42.3.1"]
}

Let's try launch a pySpark script to Apache Livy Server

params = {"host": "localhost", "port":"5432", "database": "db", "table":"staging", "user": "postgres", "password": "pg12345"}
pyspark_script = """

    from pyspark.sql.functions import udf, col, explode
    from pyspark.sql.types import StructType, StructField, IntegerType, StringType, ArrayType
    from pyspark.sql import Row
    from pyspark.sql import SparkSession


    df = spark.read.format("jdbc") \
        .option("url", "jdbc:postgresql://{host}:{port}/{database}") \
        .option("driver", "org.postgresql.Driver") \
        .option("dbtable", "{table}") \
        .option("user", "{user}") \
        .option("password", "{password}") \
        .load()
        
    n_rows = df.count()

    spark.stop()
"""

Creating an livyc Object

lvy = livyc.LivyC(data_livy)

Creating a new session to Apache Livy Server

session = lvy.create_session()

Send and execute script in the Apache Livy server

lvy.run_script(session, pyspark_script.format(**params))

Accesing to the variable "n_rows" available in the session

lvy.read_variable(session, "n_rows")

Contributing and Feedback

Any ideas or feedback about this repository?. Help me to improve it.

Authors

License

This project is licensed under the terms of the MIT License.

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

livyc-0.0.14.tar.gz (19.2 kB view details)

Uploaded Source

Built Distribution

livyc-0.0.14-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file livyc-0.0.14.tar.gz.

File metadata

  • Download URL: livyc-0.0.14.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.9

File hashes

Hashes for livyc-0.0.14.tar.gz
Algorithm Hash digest
SHA256 deb00a241be04e263a8d8953e16fb2a7a1cbef2105656ee3520761b7c0b7f99a
MD5 7944d2a1123c8ce6e902f48877197416
BLAKE2b-256 35226f708f83bf32ec9c0a1602ebbd0909cfe77e12acae021eb98c40c989a552

See more details on using hashes here.

File details

Details for the file livyc-0.0.14-py3-none-any.whl.

File metadata

  • Download URL: livyc-0.0.14-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.9

File hashes

Hashes for livyc-0.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 48275bb03be428a53807b72c013997ed4d93e9cd5b60c8306f30c953668d0b63
MD5 94ac159b1cbff8fa3a504dbf177ba417
BLAKE2b-256 de1973efa5de78483692b61cbbd0a569030c228f833f23e49f7c44da638d689e

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