Skip to content

Commit 6634164

Browse files
committed
Clean up
1 parent 0c0f761 commit 6634164

File tree

19 files changed

+85
-94
lines changed

19 files changed

+85
-94
lines changed

jigsawstack/__init__.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
import os
2-
from ._client import JigsawStack
3-
4-
# Config vars
5-
api_key = os.environ.get("JIGSAWSTACK_API_KEY", "")
6-
api_url = os.environ.get("JIGSAWSTACK_API_URL", "https://api.jigsawstack.com")
71

2+
from ._client import JigsawStack
83

94
# Create a global instance of the Web class
105
__all__ = ["JigsawStack"]

jigsawstack/_client.py

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
1-
2-
from . import resources
31
from typing import Union
4-
from ._config import ClientConfig
52
import os
6-
3+
from .audio import Audio
4+
from .vision import Vision
5+
from .search import Search
6+
from .prediction import Prediction
7+
from .sql import SQL
8+
from .store import KV, File
9+
from .translate import Translate
10+
from .web import Web
11+
from .sentiment import Sentiment
12+
from .validate import Validate
13+
from .summary import Summary
714

815
class JigsawStack:
9-
audio: resources.Audio
10-
vision : resources.Vision
11-
prediction: resources.Prediction
12-
sql: resources.SQL
13-
file: resources.File
14-
kv: resources.KV
15-
translate: resources.Translate
16-
web: resources.Web
17-
sentiment: resources.Sentiment
18-
validate: resources.Validate
19-
summary: resources.Summary
20-
search: resources.Search
16+
audio: Audio
17+
vision : Vision
18+
prediction: Prediction
19+
sql: SQL
20+
file: File
21+
kv: KV
22+
translate: Translate
23+
web: Web
24+
sentiment: Sentiment
25+
validate: Validate
26+
summary: Summary
27+
search: Search
2128
api_key: str
2229
api_url: str
2330

@@ -38,15 +45,15 @@ def __init__(self, api_key: Union[str, None] = None, api_url: Union[str, None] =
3845
self.api_url = api_url
3946

4047

41-
self.audio = resources.Audio(api_key=api_key, api_url=api_url)
42-
self.web = resources.Web(api_key=api_key, api_url=api_url)
43-
self.search = resources.Search(api_key=api_key, api_url=api_url)
44-
self.sentiment = resources.Sentiment(api_key=api_key, api_url=api_url)
45-
self.validate = resources.Validate(api_key=api_key, api_url=api_url)
46-
self.summary = resources.Summary(api_key=api_key, api_url=api_url)
47-
self.vision = resources.Vision(api_key=api_key, api_url=api_url)
48-
self.prediction = resources.Prediction(api_key=api_key, api_url=api_url)
49-
self.sql = resources.SQL(api_key=api_key, api_url=api_url)
50-
self.file = resources.File(api_key=api_key, api_url=api_url)
51-
self.kv = resources.KV(api_key=api_key, api_url=api_url)
52-
self.translate = resources.Translate(api_key=api_key, api_url=api_url)
48+
self.audio = Audio(api_key=api_key, api_url=api_url)
49+
self.web = Web(api_key=api_key, api_url=api_url)
50+
self.search = Search(api_key=api_key, api_url=api_url)
51+
self.sentiment = Sentiment(api_key=api_key, api_url=api_url)
52+
self.validate = Validate(api_key=api_key, api_url=api_url)
53+
self.summary = Summary(api_key=api_key, api_url=api_url)
54+
self.vision = Vision(api_key=api_key, api_url=api_url)
55+
self.prediction = Prediction(api_key=api_key, api_url=api_url)
56+
self.sql = SQL(api_key=api_key, api_url=api_url)
57+
self.file = File(api_key=api_key, api_url=api_url)
58+
self.kv = KV(api_key=api_key, api_url=api_url)
59+
self.translate = Translate(api_key=api_key, api_url=api_url)

jigsawstack/audio/audio.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
from typing import Any, Dict, List, cast
22
from typing_extensions import NotRequired, TypedDict
3-
from jigsawstack import request
3+
from ..request import Request
44
from ._audio import SpeechToTextParams, SpeechToTextResponse
55
from .._config import ClientConfig
66
class Audio(ClientConfig):
7-
87
def speech_to_text(self, params: SpeechToTextParams) -> SpeechToTextResponse:
98
path = "/ai/transcribe"
10-
resp = request.Request(
9+
resp = Request(
1110
api_key=self.api_key,
1211
api_url=self.api_url,
1312
path=path, params=cast(Dict[Any, Any], params), verb="post"

jigsawstack/prediction/_prediction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Dict, List, Union, cast
22
from typing_extensions import NotRequired, TypedDict
3-
from jigsawstack import request
3+
from ..request import Request
44
from typing import List, Union
55
from .._config import ClientConfig
66

@@ -39,7 +39,7 @@ class PredictionResponse(TypedDict):
3939
class Prediction(ClientConfig):
4040
def predict(self, params: PredictionParams) -> PredictionResponse:
4141
path = "/ai/prediction"
42-
resp = request.Request(
42+
resp = Request(
4343
api_key=self.api_key,
4444
api_url=self.api_url,
4545
path=path,params=cast(Dict[Any, Any], params),verb="post").perform_with_content()

jigsawstack/request.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
from typing import Any, Dict, Generic, List, Union, cast
2-
32
import requests
43
from typing_extensions import Literal, TypeVar
5-
6-
import jigsawstack
7-
from jigsawstack.exceptions import NoContentError, raise_for_code_and_type
4+
from .exceptions import NoContentError, raise_for_code_and_type
85

96
RequestVerb = Literal["get", "post", "put", "patch", "delete"]
107

jigsawstack/search/_search.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Dict, List, cast
22
from typing_extensions import NotRequired, TypedDict
3-
from jigsawstack import request
3+
from ..request import Request
44
from typing_extensions import NotRequired, TypedDict
55
from .._config import ClientConfig
66

@@ -61,7 +61,7 @@ def ai_search(self,params: AISearchParams) -> SearchAIResponse:
6161
safe_search = params.get("safe_search","moderate")
6262
spell_check = params.get("spell_check", "True")
6363
path = f"/web/search?query={query}&ai_overview={ai_overview}&safe_search={safe_search}&spell_check={spell_check}"
64-
resp = request.Request(
64+
resp = Request(
6565
api_key=self.api_key,
6666
api_url=self.api_url,
6767
path=path, params=cast(Dict[Any, Any], params), verb="GET"
@@ -74,7 +74,7 @@ def ai_search(self,params: AISearchParams) -> SearchAIResponse:
7474
def suggestion(self, params: SearchSuggestionParams) -> SearchSuggestionResponse:
7575
query = params["query"]
7676
path = f"/web/search/suggest?query={query}"
77-
resp = request.Request(
77+
resp = Request(
7878
api_key=self.api_key,
7979
api_url=self.api_url,
8080
path=path, params=cast(Dict[Any, Any], params), verb="GET"

jigsawstack/sentiment/_sentiment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Dict, List, Union, cast
22
from typing_extensions import NotRequired, TypedDict
3-
from jigsawstack import request
3+
from ..request import Request
44
from typing import List, Union
55
from .._config import ClientConfig
66

@@ -37,6 +37,6 @@ class SentimentResponse(TypedDict):
3737
class Sentiment(ClientConfig):
3838
def analyze(self, params: SentimentParams) -> SentimentResponse:
3939
path = "/ai/sentiment"
40-
resp = request.Request(api_key=self.api_key,
40+
resp = Request(api_key=self.api_key,
4141
api_url=self.api_url,path=path,params=cast(Dict[Any, Any], params),verb="post").perform_with_content()
4242
return resp

jigsawstack/sql/_sql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Dict, List, Union, cast
22
from typing_extensions import NotRequired, TypedDict
3-
from jigsawstack import request
3+
from ..request import Request
44
from typing import List, Union
55
from .._config import ClientConfig
66

@@ -37,7 +37,7 @@ class SQL(ClientConfig):
3737
@classmethod
3838
def text_to_sql(self, params: SQLParams) -> SQLResponse:
3939
path = "/ai/sql"
40-
resp = request.Request(
40+
resp = Request(
4141
api_key=self.api_key,
4242
api_url=self.api_url,
4343
path=path,params=cast(Dict[Any, Any], params),verb="post").perform_with_content()

jigsawstack/store/file.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Dict, List, cast
22
from typing_extensions import NotRequired, TypedDict
3-
from jigsawstack import request
3+
from ..request import Request
44
from ._file import FileDeleteResponse
55
from .._config import ClientConfig
66

@@ -10,7 +10,7 @@ class File(ClientConfig):
1010

1111
def get(self, key: str) -> Any:
1212
path =f"/store/file/{key}"
13-
resp = request.Request(
13+
resp = Request(
1414
api_key=self.api_key,
1515
api_url=self.api_url,
1616
path=path, params=cast(Dict[Any, Any], params={}), verb="get"
@@ -19,7 +19,7 @@ def get(self, key: str) -> Any:
1919

2020
def delete(self, key: str) -> FileDeleteResponse:
2121
path =f"/store/file/{key}"
22-
resp = request.Request(
22+
resp = Request(
2323
api_key=self.api_key,
2424
api_url=self.api_url,
2525
path=path, params=cast(Dict[Any, Any], params={}), verb="delete"

jigsawstack/store/kv.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Dict, List, cast
22
from typing_extensions import NotRequired, TypedDict
3-
from jigsawstack import request
3+
from ..request import Request
44
from ._kv import KVAddParams, KVAddResponse, KVGetResponse
55
from .._config import ClientConfig
66

@@ -9,7 +9,7 @@ class KV(ClientConfig):
99

1010
def add(self, params: KVAddParams) -> KVAddResponse:
1111
path = "/store/kv"
12-
resp = request.Request(
12+
resp = Request(
1313
api_key=self.api_key,
1414
api_url=self.api_url,
1515
path=path, params=cast(Dict[Any, Any], params), verb="post"
@@ -18,7 +18,7 @@ def add(self, params: KVAddParams) -> KVAddResponse:
1818

1919
def get(self, key: str) -> KVGetResponse:
2020
path =f"/store/kv/{key}"
21-
resp = request.Request(
21+
resp = Request(
2222
api_key=self.api_key,
2323
api_url=self.api_url,
2424
path=path, params=cast(Dict[Any, Any], params={}), verb="get"
@@ -28,7 +28,7 @@ def get(self, key: str) -> KVGetResponse:
2828

2929
def delete(self, key: str) -> KVGetResponse:
3030
path =f"/store/kv/{key}"
31-
resp = request.Request(
31+
resp = Request(
3232
api_key=self.api_key,
3333
api_url=self.api_url,
3434
path=path, params=cast(Dict[Any, Any], params={}), verb="delete"

jigsawstack/summary/_summary.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Dict, List, Union, cast
22
from typing_extensions import NotRequired, TypedDict
3-
from jigsawstack import request
3+
from ..request import Request
44
from typing import List, Union
55
from .._config import ClientConfig
66

@@ -32,7 +32,7 @@ class Summary(ClientConfig):
3232

3333
def summarize(self,params: SummaryParams) -> SummaryResponse:
3434
path = "/ai/summary"
35-
resp = request.Request(
35+
resp = Request(
3636
api_key=self.api_key,
3737
api_url=self.api_url,
3838
path=path,params=cast(Dict[Any, Any], params),verb="post").perform_with_content()

jigsawstack/translate/_translate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Dict, List, Union, cast
22
from typing_extensions import NotRequired, TypedDict
3-
from jigsawstack import request
3+
from ..request import Request
44
from typing import List, Union
55
from .._config import ClientConfig
66

@@ -31,7 +31,7 @@ class TranslateResponse(TypedDict):
3131
class Translate(ClientConfig):
3232
def translate(self, params: TranslateParams) -> TranslateResponse:
3333
path = "/ai/translate"
34-
resp = request.Request(
34+
resp = Request(
3535
api_key=self.api_key,
3636
api_url=self.api_url,
3737
path=path,params=cast(Dict[Any, Any], params),verb="post").perform_with_content()

jigsawstack/validate/validate.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Dict, List, cast
22
from typing_extensions import NotRequired, TypedDict
3-
from jigsawstack import request
3+
from ..request import Request
44
from ._validate import EmailValidationParams, EmailValidationResponse, NSFWParams, NSFWResponse, ProfanityParams, ProfanityResponse,SpellCheckParams, SpellCheckResponse, SpamCheckParams, SpamCheckResponse
55
from .._config import ClientConfig
66

@@ -9,7 +9,7 @@ class Validate(ClientConfig):
99
def email(self, params: EmailValidationParams) -> EmailValidationResponse:
1010
email = params.get('email')
1111
path = f"/validate/email?email={email}"
12-
resp = request.Request(
12+
resp = Request(
1313
api_url=self.api_url,
1414
api_key=self.api_key,
1515
path=path, params=cast(Dict[Any, Any], params), verb="get"
@@ -19,7 +19,7 @@ def email(self, params: EmailValidationParams) -> EmailValidationResponse:
1919
def nsfw(self, params: NSFWParams) -> NSFWResponse:
2020
url = params.get("url")
2121
path = f"/validate/nsfw?url={url}"
22-
resp = request.Request(
22+
resp = Request(
2323
api_url=self.api_url,
2424
api_key=self.api_key,
2525
path=path, params=cast(Dict[Any, Any], params), verb="get"
@@ -31,7 +31,7 @@ def profanity(self, params: ProfanityParams) -> ProfanityResponse:
3131
text = params.get("text")
3232
censor_replacement = params.get("censor_replacement", "*")
3333
path = f"/validate/profanity?text={text}&censor_replacement={censor_replacement}"
34-
resp = request.Request(
34+
resp = Request(
3535
api_url=self.api_url,
3636
api_key=self.api_key,
3737
path=path, params=cast(Dict[Any, Any], params), verb="get"
@@ -43,15 +43,15 @@ def spell_check(self, params: SpellCheckParams) -> SpellCheckResponse:
4343
text = params.get("text")
4444
language_code = params.get("language_code","en")
4545
path = f"/validate/spell_check?text={text}&language_code={language_code}"
46-
resp = request.Request(
46+
resp = Request(
4747
api_url=self.api_url,
4848
api_key=self.api_key,
4949
path=path, params=cast(Dict[Any, Any], params), verb="get"
5050
).perform_with_content()
5151
return resp
5252
def spam_check(self, params: SpamCheckParams) -> SpamCheckResponse:
5353
path = "/ai/spamcheck"
54-
resp = request.Request(
54+
resp = Request(
5555
api_url=self.api_url,
5656
api_key=self.api_key,
5757
path=path, params=cast(Dict[Any, Any], params), verb="post"

jigsawstack/vision/vision.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
from typing import Any, Dict, List, cast
22
from typing_extensions import NotRequired, TypedDict
3-
from jigsawstack import request
3+
from ..request import Request
44
from ._vision import VOCRParams, OCRResponse,OCRParams
55
from .._config import ClientConfig
66
class Vision(ClientConfig):
77
def vocr(self, params: VOCRParams) -> OCRResponse:
88
path = "/ai/vocr"
9-
resp = request.Request(
9+
resp = Request(
1010
api_key=self.api_key,
1111
api_url=self.api_url,
1212
path=path, params=cast(Dict[Any, Any], params), verb="post"
1313
).perform_with_content()
1414
return resp
1515
def object_detection(self, params: OCRParams) -> OCRResponse:
1616
path = "/ai/object_detection"
17-
resp = request.Request(
17+
resp = Request(
1818
api_key=self.api_key,
1919
api_url=self.api_url,
2020
path=path, params=cast(Dict[Any, Any], params), verb="post"

jigsawstack/web/search.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Any, Dict, List, cast
22
from typing_extensions import NotRequired, TypedDict
3-
from jigsawstack import request
3+
from ..request import Request
44
from typing_extensions import NotRequired, TypedDict
55

66

@@ -58,7 +58,7 @@ class Search:
5858
@classmethod
5959
def ai_search(params: AISearchParams) -> SearchAIResponse:
6060
path = "/web/search"
61-
resp = request.Request(
61+
resp = Request(
6262
path=path, params=cast(Dict[Any, Any], params), verb="post"
6363
).perform_with_content()
6464
return resp
@@ -67,7 +67,7 @@ def ai_search(params: AISearchParams) -> SearchAIResponse:
6767
@classmethod
6868
def suggestion(params: SearchSuggestionParams) -> SearchSuggestionResponse:
6969
path = "/web/search/suggest"
70-
resp = request.Request(
70+
resp = Request(
7171
path=path, params=cast(Dict[Any, Any], params), verb="patch"
7272
).perform_with_content()
7373
return resp

0 commit comments

Comments
 (0)