Skip to main content

GlassFlow Python Client SDK

Project description



License: MIT Chat on Slack Ruff

GlassFlow Python SDK

The GlassFlow Python SDK provides a convenient way to interact with the GlassFlow API in your Python applications. The SDK is used to publish and consume events to your GlassFlow pipelines.

Installation

You can install the GlassFlow Python SDK using pip:

pip install glassflow

Data Operations

publish

Publish a new event into the pipeline

Example Usage

from glassflow import PipelineDataSource

source = PipelineDataSource(pipeline_id="<str value", pipeline_access_token="<str token>")
data = {} # your json event
res = source.publish(request_body=data)

if res.status_code == 200:
    print("Published sucessfully")

consume

Consume the transformed event from the pipeline

Example Usage

from glassflow import PipelineDataSink

sink = PipelineDataSink(pipeline_id="<str value", pipeline_access_token="<str value>")
res = sink.consume()

if res.status_code == 200:
    print(res.json())

consume failed

If the transformation failed for any event, they are available in a failed queue. You can consume those events from the pipeline

Example Usage

from glassflow import PipelineDataSink

sink = PipelineDataSink(pipeline_id="<str value", pipeline_access_token="<str value>")
res = sink.consume_failed()

if res.status_code == 200:
    print(res.json())

validate credentials

Validate pipeline credentials (pipeline_id and pipeline_access_token) from source or sink

Example Usage

from glassflow import PipelineDataSource, errors

try:
    source = PipelineDataSource(pipeline_id="<str value", pipeline_access_token="<str value>")
    source.validate_credentials()
except errors.PipelineNotFoundError as e:
    print("Pipeline ID does not exist!")
    raise e
except errors.PipelineAccessTokenInvalidError as e:
    print("Pipeline Access Token is invalid!")
    raise e

Pipeline Management

In order to manage your pipelines with this SDK, one needs to provide the PERSONAL_ACCESS_TOKEN to the GlassFlow client.

from glassflow import GlassFlowClient

client = GlassFlowClient(personal_access_token="<your personal access token>")

Now you can perform CRUD operations on your pipelines:

  • list_pipelines - Returns the list of pipelines available
  • get_pipeline - Returns a pipeline object from a given pipeline ID
  • create - Create a new pipeline
  • delete - Delete an existing pipeline

list_pipelines

Returns information about the available pipelines. It can be restricted to a specific space by passing the space_id.

Example Usage

from glassflow import GlassFlowClient

client = GlassFlowClient(personal_access_token="<your access token>")
res = client.list_pipelines()

get_pipeline

Gets information about a pipeline from a given pipeline ID. It returns a Pipeline object which can be used manage the Pipeline.

Example Usage

from glassflow import GlassFlowClient

client = GlassFlowClient(personal_access_token="<your access token>")
pipeline = client.get_pipeline(pipeline_id="<your pipeline id>")

print("Name:", pipeline.name)

create

The Pipeline object has a create method that creates a new GlassFlow pipeline.

Example Usage

from glassflow import Pipeline

pipeline = Pipeline(
    name="<your pipeline name>",
    transformation_file="path/to/transformation.py",
    space_id="<your space id>",
    personal_access_token="<your personal access token>"
).create()

In the next example we create a pipeline with Google PubSub source and a webhook sink:

from glassflow import Pipeline

pipeline = Pipeline(
    name="<your pipeline name>",
    transformation_file="path/to/transformation.py",
    space_id="<your space id>",
    personal_access_token="<your personal access token>",
    source_kind="google_pubsub",
    source_config={
        "project_id": "<your gcp project id>",
        "subscription_id": "<your subscription id>",
        "credentials_json": "<your credentials json>"
    },
    sink_kind="webhook",
    sink_config={
        "url": "<webhook url>",
        "method": "<GET | POST | PUT | PATCH | DELETE>",
        "headers": [{"header1": "header1_value"}]
    }
).create()

delete

The Pipeline object has a delete method to delete a pipeline

Example Usage

from glassflow import Pipeline

pipeline = Pipeline(
    name="<your pipeline name>",
    transformation_file="path/to/transformation.py",
    space_id="<your space id>",
    personal_access_token="<your personal access token>"
).create()

pipeline.delete()

Quickstart

Follow the quickstart guide here

Code Samples

GlassFlow Examples

SDK Maturity

Please note that the GlassFlow Python SDK is currently in beta and is subject to potential breaking changes. We recommend keeping an eye on the official documentation and updating your code accordingly to ensure compatibility with future versions of the SDK.

User Guides

For more detailed information on how to use the GlassFlow Python SDK, please refer to the GlassFlow Documentation. The documentation provides comprehensive guides, tutorials, and examples to help you get started with GlassFlow and make the most out of the SDK.

Contributing

Anyone who wishes to contribute to this project, whether documentation, features, bug fixes, code cleanup, testing, or code reviews, is very much encouraged to do so.

  1. Join the Slack channel.

  2. Just raise your hand on the GitHub discussion board.

If you are unfamiliar with how to contribute to GitHub projects, here is a Get Started Guide. A full set of contribution guidelines, along with templates, are in progress.

Troubleshooting

For any questions, comments, or additional help, please reach out to us via email at help@glassflow.dev. Please check out our Q&A to get solutions for common installation problems and other issues.

Raise an issue

To provide feedback or report a bug, please raise an issue on our issue tracker.

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

glassflow-2.0.6.tar.gz (25.5 kB view details)

Uploaded Source

Built Distribution

glassflow-2.0.6-py3-none-any.whl (30.1 kB view details)

Uploaded Python 3

File details

Details for the file glassflow-2.0.6.tar.gz.

File metadata

  • Download URL: glassflow-2.0.6.tar.gz
  • Upload date:
  • Size: 25.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for glassflow-2.0.6.tar.gz
Algorithm Hash digest
SHA256 d2c82678c8e15e4c05e0b50088f1186ab686525a7b6a3c1fac5d573e4ad51f0f
MD5 23a341c8d192ae9ffbf72fa0f1b6f0e3
BLAKE2b-256 fa4aa6859970a6c1bfbb97de34a155e9b6207ec718ed7423f6eca11a2bf82ea5

See more details on using hashes here.

Provenance

The following attestation bundles were made for glassflow-2.0.6.tar.gz:

Publisher: publish_pypi.yaml on glassflow/glassflow-python-sdk

Attestations:

File details

Details for the file glassflow-2.0.6-py3-none-any.whl.

File metadata

  • Download URL: glassflow-2.0.6-py3-none-any.whl
  • Upload date:
  • Size: 30.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for glassflow-2.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 adb8c98c2a1c090325ac652f1631b90208e0744f5d0c7b74ae5d4e23e164d23a
MD5 a580a83648cd067e1ce49cf0d37b12d9
BLAKE2b-256 a2b418589f24dd7fbfbb67c23dac668fa5853a0eaeba9ce724f7daec1b025bf0

See more details on using hashes here.

Provenance

The following attestation bundles were made for glassflow-2.0.6-py3-none-any.whl:

Publisher: publish_pypi.yaml on glassflow/glassflow-python-sdk

Attestations:

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