Skip to content

Commit

Permalink
Merge pull request #19 from glassflow/pablo/dev-177-add-pipeline-chec…
Browse files Browse the repository at this point in the history
…k-method-to-sdk

Pablo/dev 177 add pipeline check method to sdk
  • Loading branch information
PabloPardoGarcia authored Sep 5, 2024
2 parents c215810 + 5087eee commit 1834a7c
Show file tree
Hide file tree
Showing 22 changed files with 730 additions and 395 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/on_pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Test GlassFlow Python SDK

on:
pull_request:
branches:
- main

jobs:
tests:
name: Run pytest tests
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python environment
uses: actions/setup-python@v5
with:
python-version: "3.x"
cache: 'pip'
cache-dependency-path: setup.py

- name: Install dependencies
run: pip install -e .[dev]

- name: Run Integration Tests
run: pytest tests/glassflow/integration_tests/
env:
PIPELINE_ID: ${{ secrets.PIPELINE_ID }}
PIPELINE_ACCESS_TOKEN: ${{ secrets.PIPELINE_ACCESS_TOKEN }}

checks:
name: Run code checks
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Python environment
uses: actions/setup-python@v5
with:
python-version: "3.x"
cache: 'pip'
cache-dependency-path: setup.py

- name: Install dependencies
run: pip install -e .[dev]

- name: Run isort
run: isort .

- name: Run linter and code formatter
run: ruff check .
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ utils.bak.py
site**
.pypirc
dist/
build
build
.env
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<a href="https://join.slack.com/t/glassflowhub/shared_invite/zt-2g3s6nhci-bb8cXP9g9jAQ942gHP5tqg">
<img src="https://img.shields.io/badge/slack-join-community?logo=slack&amp;logoColor=white&amp;style=flat"
alt="Chat on Slack"></a>
<a href="https://github.com/astral-sh/ruff"><img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff" style="max-width:100%;"></a>


# GlassFlow Python SDK

Expand Down
5 changes: 2 additions & 3 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
import glassflow

client = glassflow.GlassFlowClient()
pipeline = client.pipeline_client(space_id="<space_id>", pipeline_id="<pipeline_id>")
pipeline_access_token="<pipeline_token>"
pipeline = client.pipeline_client(pipeline_id="<pipeline_id>", pipeline_access_token="<pipeline_token>")
data = {
"name": "Hello World",
"id": 1
}
res = pipeline.publish(request_body=data,pipeline_access_token=pipeline_access_token)
res = pipeline.publish(request_body=data)
```
31 changes: 21 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,32 @@
description="GlassFlow Python Client SDK",
url="https://learn.glassflow.dev/docs",
project_urls={
'Source': 'https://github.com/glassflow/glassflow-python-sdk',
"Source": "https://github.com/glassflow/glassflow-python-sdk",
},
long_description=long_description,
long_description_content_type="text/markdown",
packages=setuptools.find_packages(where="src"),
install_requires=[
"urllib3==1.26.15", "certifi>=2023.7.22", "charset-normalizer>=3.2.0",
"dataclasses-json>=0.6.4", "idna>=3.4", "jsonpath-python>=1.0.6 ",
"marshmallow>=3.19.0", "mypy-extensions>=1.0.0", "packaging>=23.1",
"python-dateutil>=2.8.2", "requests>=2.31.0", "six>=1.16.0",
"typing-inspect>=0.9.0", "typing_extensions>=4.7.1",
"python-dotenv==1.0.1"
"urllib3==1.26.15",
"certifi>=2023.7.22",
"charset-normalizer>=3.2.0",
"dataclasses-json>=0.6.4",
"idna>=3.4",
"jsonpath-python>=1.0.6 ",
"marshmallow>=3.19.0",
"mypy-extensions>=1.0.0",
"packaging>=23.1",
"python-dateutil>=2.8.2",
"requests>=2.31.0",
"six>=1.16.0",
"typing-inspect>=0.9.0",
"typing_extensions>=4.7.1",
"python-dotenv==1.0.1",
],
extras_require={"dev": ["pylint==2.16.2"]},
package_dir={'': 'src'},
python_requires='>=3.8',
extras_require={
"dev": ["pylint==2.16.2", "pytest==8.3.2", "isort==5.13.2", "ruff==0.6.3"]
},
package_dir={"": "src"},
python_requires=">=3.8",
package_data={"glassflow": ["py.typed"]},
)
5 changes: 2 additions & 3 deletions src/glassflow/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

from .client import GlassFlowClient
from .config import GlassFlowConfig
from .client import GlassFlowClient as GlassFlowClient
from .config import GlassFlowConfig as GlassFlowConfig
34 changes: 20 additions & 14 deletions src/glassflow/client.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""GlassFlow Python Client to interact with GlassFlow API
"""
"""GlassFlow Python Client to interact with GlassFlow API"""

from .pipelines import PipelineClient
import os
from typing import Optional
from .config import GlassFlowConfig

import requests as requests_http
import os

from .config import GlassFlowConfig
from .pipelines import PipelineClient


class GlassFlowClient:
Expand All @@ -17,6 +18,7 @@ class GlassFlowClient:
organization_id: Organization ID of the user. If not provided, the default organization will be used
"""

glassflow_config: GlassFlowConfig

def __init__(self, organization_id: str = None) -> None:
Expand All @@ -29,10 +31,12 @@ def __init__(self, organization_id: str = None) -> None:
self.glassflow_config = GlassFlowConfig(rclient)
self.organization_id = organization_id

def pipeline_client(self,
pipeline_id: Optional[str] = None,
pipeline_access_token: Optional[str] = None,
space_id: Optional[str] = None) -> PipelineClient:
def pipeline_client(
self,
pipeline_id: Optional[str] = None,
pipeline_access_token: Optional[str] = None,
space_id: Optional[str] = None,
) -> PipelineClient:
"""Create a new PipelineClient object to interact with a specific pipeline
Args:
Expand All @@ -44,9 +48,9 @@ def pipeline_client(self,
"""
# if no pipeline_id or pipeline_access_token is provided, try to read from environment variables
if not pipeline_id:
pipeline_id = os.getenv('PIPELINE_ID')
pipeline_id = os.getenv("PIPELINE_ID")
if not pipeline_access_token:
pipeline_access_token = os.getenv('PIPELINE_ACCESS_TOKEN')
pipeline_access_token = os.getenv("PIPELINE_ACCESS_TOKEN")
# no pipeline_id provided explicitly or in environment variables
if not pipeline_id:
raise ValueError(
Expand All @@ -57,6 +61,8 @@ def pipeline_client(self,
"PIPELINE_ACCESS_TOKEN must be set as an environment variable or provided explicitly"
)

return PipelineClient(glassflow_client=self,
pipeline_id=pipeline_id,
pipeline_access_token=pipeline_access_token)
return PipelineClient(
glassflow_client=self,
pipeline_id=pipeline_id,
pipeline_access_token=pipeline_access_token,
)
12 changes: 7 additions & 5 deletions src/glassflow/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from dataclasses import dataclass
import requests
from importlib.metadata import version

import requests


@dataclass
class GlassFlowConfig:
Expand All @@ -14,8 +15,9 @@ class GlassFlowConfig:
user_agent: The user agent to be used in the requests
"""

client: requests.Session
server_url: str = 'https://api.glassflow.dev/v1'
sdk_version: str = version('glassflow')
user_agent: str = 'glassflow-python-sdk/{}'.format(sdk_version)
glassflow_client: str = 'python-sdk/{}'.format(sdk_version)
server_url: str = "https://api.glassflow.dev/v1"
sdk_version: str = version("glassflow")
user_agent: str = "glassflow-python-sdk/{}".format(sdk_version)
glassflow_client: str = "python-sdk/{}".format(sdk_version)
4 changes: 2 additions & 2 deletions src/glassflow/models/errors/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .error import *
from .clienterror import *
from .clienterror import ClientError
from .error import Error

__all__ = ["Error", "ClientError"]
16 changes: 11 additions & 5 deletions src/glassflow/models/errors/clienterror.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ class ClientError(Exception):
raw_response: The raw response object
"""

detail: str
status_code: int
body: str
raw_response: requests_http.Response

def __init__(self, detail: str, status_code: int, body: str,
raw_response: requests_http.Response):
def __init__(
self,
detail: str,
status_code: int,
body: str,
raw_response: requests_http.Response,
):
"""Create a new ClientError object
Args:
Expand All @@ -38,8 +44,8 @@ def __str__(self):
str: The string representation of the error
"""
body = ''
body = ""
if len(self.body) > 0:
body = f'\n{self.body}'
body = f"\n{self.body}"

return f'{self.detail}: Status {self.status_code}{body}'
return f"{self.detail}: Status {self.status_code}{body}"
12 changes: 7 additions & 5 deletions src/glassflow/models/errors/error.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import annotations

import dataclasses

from dataclasses_json import Undefined, dataclass_json

from glassflow import utils


Expand All @@ -13,11 +16,10 @@ class Error(Exception):
message: A message describing the error
"""
detail: str = dataclasses.field(metadata={
'dataclasses_json': {
'letter_case': utils.get_field_name('detail')
}
})

detail: str = dataclasses.field(
metadata={"dataclasses_json": {"letter_case": utils.get_field_name("detail")}}
)

def __str__(self) -> str:
return utils.marshal_json(self, type(self))
25 changes: 18 additions & 7 deletions src/glassflow/models/operations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
from .publishevent import *
from .consumeevent import *
from .consumefailed import *
from .consumeevent import (ConsumeEventRequest, ConsumeEventResponse,
ConsumeEventResponseBody)
from .consumefailed import (ConsumeFailedRequest, ConsumeFailedResponse,
ConsumeFailedResponseBody)
from .publishevent import (PublishEventRequest, PublishEventRequestBody,
PublishEventResponse, PublishEventResponseBody)
from .status_access_token import StatusAccessTokenRequest

__all__ = [
"PublishEventRequest", "PublishEventRequestBody", "PublishEventResponse",
"PublishEventResponseBody", "ConsumeEventRequest", "ConsumeEventResponse",
"ConsumeEventResponseBody", "ConsumeFailedRequest",
"ConsumeFailedResponse", "ConsumeFailedResponseBody"
"PublishEventRequest",
"PublishEventRequestBody",
"PublishEventResponse",
"PublishEventResponseBody",
"ConsumeEventRequest",
"ConsumeEventResponse",
"ConsumeEventResponseBody",
"ConsumeFailedRequest",
"ConsumeFailedResponse",
"ConsumeFailedResponseBody",
"StatusAccessTokenRequest",
]
Loading

0 comments on commit 1834a7c

Please sign in to comment.