tinybird 0.0.1.dev61__py3-none-any.whl → 0.0.1.dev62__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of tinybird might be problematic. Click here for more details.

tinybird/tb/__cli__.py CHANGED
@@ -4,5 +4,5 @@ __description__ = 'Tinybird Command Line Tool'
4
4
  __url__ = 'https://www.tinybird.co/docs/cli/introduction.html'
5
5
  __author__ = 'Tinybird'
6
6
  __author_email__ = 'support@tinybird.co'
7
- __version__ = '0.0.1.dev61'
8
- __revision__ = '0fed0e1'
7
+ __version__ = '0.0.1.dev62'
8
+ __revision__ = '472a5f2'
@@ -10,6 +10,7 @@ from urllib.parse import urlencode
10
10
 
11
11
  import click
12
12
  import humanfriendly
13
+ import pyperclip
13
14
  import requests
14
15
  from click import Context
15
16
 
@@ -54,7 +55,7 @@ async def endpoint_ls(ctx: Context, match: str, format_: str):
54
55
  tk = get_name_version(t["name"])
55
56
  if pattern and not pattern.search(tk["name"]):
56
57
  continue
57
- token = get_endpoint_token(tokens, tk["name"])
58
+ token = get_endpoint_token(tokens, tk["name"]) or client.token
58
59
  endpoint_url = build_endpoint_url(client, tk["name"], token)
59
60
  table_human_readable.append((tk["name"], t["updated_at"][:-7], len(t["nodes"]), endpoint_url))
60
61
  table_machine_readable.append(
@@ -151,29 +152,23 @@ async def endpoint_data(ctx: Context, pipe: str, query: str, format_: str):
151
152
 
152
153
  @endpoint.command(name="url")
153
154
  @click.argument("pipe")
155
+ @click.option(
156
+ "--language",
157
+ default="http",
158
+ help="Language used for sending the request. Options: http, python, curl, javascript, rust, go",
159
+ )
154
160
  @click.pass_context
155
161
  @coro
156
- async def endpoint_url(ctx: Context, pipe: str):
162
+ async def endpoint_url(ctx: Context, pipe: str, language: str):
157
163
  """Print the URL of an endpoint"""
164
+ if language != "http":
165
+ click.echo(FeedbackManager.highlight(message=f"\n» Generating snippet for {language} language"))
158
166
  client: TinyB = ctx.ensure_object(dict)["client"]
159
167
  tokens = await client.tokens()
160
- token = get_endpoint_token(tokens, pipe)
161
- click.echo(build_endpoint_url(client, pipe, token))
162
-
163
-
164
- def build_endpoint_url(tb_client: TinyB, pipe_name: str, token: Optional[str]) -> Optional[str]:
165
- try:
166
- token = token or tb_client.token
167
- example_params = {
168
- "format": "json",
169
- "pipe": pipe_name,
170
- "q": "",
171
- "token": token,
172
- }
173
- response = requests.get(f"{tb_client.host}/examples/query.http?{urlencode(example_params)}")
174
- return response.text.replace("http://localhost:8001", tb_client.host)
175
- except Exception:
176
- return None
168
+ token = get_endpoint_token(tokens, pipe) or client.token
169
+ click.echo(build_endpoint_snippet(client, pipe, token, language))
170
+ if language != "http":
171
+ click.echo(FeedbackManager.success(message="\n✓ Code snippet copied to clipboard!\n"))
177
172
 
178
173
 
179
174
  def get_endpoint_token(tokens: List[Dict[str, Any]], pipe_name: str) -> Optional[str]:
@@ -272,3 +267,104 @@ async def endpoint_stats(ctx: click.Context, pipes: Tuple[str, ...], format_: st
272
267
  click.echo(json.dumps({"pipes": table_machine_readable}, indent=2))
273
268
  else:
274
269
  echo_safe_humanfriendly_tables_format_smart_table(table_human_readable, column_names=columns)
270
+
271
+
272
+ def build_endpoint_snippet(tb_client: TinyB, pipe_name: str, token: Optional[str], language: str) -> Optional[str]:
273
+ endpoint_url = build_endpoint_url(tb_client, pipe_name, token)
274
+ if language == "http":
275
+ return endpoint_url
276
+
277
+ snippet = None
278
+ if language == "python":
279
+ snippet = build_python_snippet(endpoint_url, token)
280
+ elif language == "curl":
281
+ snippet = build_curl_snippet(endpoint_url)
282
+ elif language == "javascript":
283
+ snippet = build_javascript_snippet(endpoint_url, token)
284
+ elif language == "rust":
285
+ snippet = build_rust_snippet(endpoint_url, token)
286
+ elif language == "go":
287
+ snippet = build_go_snippet(endpoint_url, token)
288
+
289
+ if not snippet:
290
+ raise CLIPipeException(FeedbackManager.error(message=f"Language {language} not supported"))
291
+
292
+ pyperclip.copy(snippet.strip())
293
+ return snippet
294
+
295
+
296
+ def build_endpoint_url(tb_client: TinyB, pipe_name: str, token: str) -> str:
297
+ example_params = {
298
+ "format": "json",
299
+ "pipe": pipe_name,
300
+ "q": "",
301
+ "token": token,
302
+ }
303
+ response = requests.get(f"{tb_client.host}/examples/query.http?{urlencode(example_params)}")
304
+ return response.text.replace("http://localhost:8001", tb_client.host)
305
+
306
+
307
+ def build_python_snippet(endpoint_url: str, token: str) -> str:
308
+ endpoint_url = endpoint_url.replace(f"token={token}", "token={{token}}")
309
+ return f"""
310
+ import requests
311
+
312
+ token = "{token}"
313
+ url = "{endpoint_url}"
314
+ response = requests.get(url)
315
+ print(response.json())
316
+ """
317
+
318
+
319
+ def build_curl_snippet(endpoint_url: str) -> str:
320
+ return f"""
321
+ curl -X GET "{endpoint_url}"
322
+ """
323
+
324
+
325
+ def build_javascript_snippet(endpoint_url: str, token: str) -> str:
326
+ endpoint_url = endpoint_url.replace(f"token={token}", "token=${token}")
327
+ return f"""
328
+ const token = "{token}";
329
+ fetch(`{endpoint_url}`)
330
+ .then(response => response.json())
331
+ .then(data => console.log(data));
332
+ """
333
+
334
+
335
+ def build_rust_snippet(endpoint_url: str) -> str:
336
+ return f"""
337
+ use reqwest::Client;
338
+
339
+ let client = Client::new();
340
+ let response = client.get("{endpoint_url}").send().await?;
341
+ """
342
+
343
+
344
+ def build_go_snippet(endpoint_url: str) -> str:
345
+ return f"""
346
+ package main
347
+
348
+ import (
349
+ "fmt"
350
+ "io"
351
+ "log"
352
+ "net/http"
353
+ )
354
+
355
+ func main() {{
356
+ url := "{endpoint_url}"
357
+ resp, err := http.Get(url)
358
+ if err != nil {{
359
+ log.Fatal(err)
360
+ }}
361
+ defer resp.Body.Close()
362
+
363
+ body, err := io.ReadAll(resp.Body)
364
+ if err != nil {{
365
+ log.Fatal(err)
366
+ }}
367
+
368
+ fmt.Println(string(body))
369
+ }}
370
+ """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tinybird
3
- Version: 0.0.1.dev61
3
+ Version: 0.0.1.dev62
4
4
  Summary: Tinybird Command Line Tool
5
5
  Home-page: https://www.tinybird.co/docs/cli/introduction.html
6
6
  Author: Tinybird
@@ -15,7 +15,7 @@ tinybird/syncasync.py,sha256=IPnOx6lMbf9SNddN1eBtssg8vCLHMt76SuZ6YNYm-Yk,27761
15
15
  tinybird/tornado_template.py,sha256=FL85SMPq2dH4JqKovmSbaolGdEzwOO91NqOzqXo2Qr0,41863
16
16
  tinybird/ch_utils/constants.py,sha256=aYvg2C_WxYWsnqPdZB1ZFoIr8ZY-XjUXYyHKE9Ansj0,3890
17
17
  tinybird/ch_utils/engine.py,sha256=OXkBhlzGjZotjD0vaT-rFIbSGV4tpiHxE8qO_ip0SyQ,40454
18
- tinybird/tb/__cli__.py,sha256=J74jDM5nA1KeHEC9VTPkVN7HFbtSPRviL37Zz3u1ywM,251
18
+ tinybird/tb/__cli__.py,sha256=Y3-22BYsp8UsmnVrY3OWWytK2xzHpGUrQRjrKGXUBhM,251
19
19
  tinybird/tb/cli.py,sha256=FD1pfbzu9YHJHEG6Vtn_EwPLTYhwqw-I6AxXeTaRHU8,926
20
20
  tinybird/tb/modules/auth.py,sha256=EzRWFmwRkXNhUmRaruEVFLdkbUg8xMSix0cAWl5D4Jg,9029
21
21
  tinybird/tb/modules/build.py,sha256=zo7qexonQ5vDNHZ1u7AK_jdo62hMfG5vWnoQBe_2oyw,9042
@@ -27,7 +27,7 @@ tinybird/tb/modules/copy.py,sha256=Aq6wh_wjRiyLQtEOKF9pKLPgJhSvbGTFWIw_LJB0t0U,5
27
27
  tinybird/tb/modules/create.py,sha256=Q7ZY4oUmEtAYpUbBLjjyiUZ6IKlkU81qJJrmdgjduOk,13914
28
28
  tinybird/tb/modules/datasource.py,sha256=TQ4wSag3CCw34d54FEXPJFGLQNYyNqv2nQbU6QT9uAE,14725
29
29
  tinybird/tb/modules/deployment.py,sha256=E3YdQgFmX7rPlgPUw9yAB0jyl7m1MQcqiQF7uHs8wK4,14272
30
- tinybird/tb/modules/endpoint.py,sha256=9arqN1JQCMb0Nd3-EJ7lukOYkGHHCpQmiiZpp5FqPhc,9432
30
+ tinybird/tb/modules/endpoint.py,sha256=M2ZerljZHLJHvDfH30r4Yma3-JGExg2PlRunb2l4r-A,11931
31
31
  tinybird/tb/modules/exceptions.py,sha256=4A2sSjCEqKUMqpP3WI00zouCWW4uLaghXXLZBSw04mY,3363
32
32
  tinybird/tb/modules/feedback_manager.py,sha256=mrw5tdYycfvg6WLXlM0KIjfJardm_aNpnJkUg2vH0cA,68463
33
33
  tinybird/tb/modules/fmt.py,sha256=poh6_cwVGSf-sBu6LKWuO2TANL_J8Sgm25sPpwxa3Aw,3558
@@ -74,8 +74,8 @@ tinybird/tb_cli_modules/config.py,sha256=6u6B5QCdiQLbJkCkwtnKGs9H3nP-KXXhC75mF7B
74
74
  tinybird/tb_cli_modules/exceptions.py,sha256=pmucP4kTF4irIt7dXiG-FcnI-o3mvDusPmch1L8RCWk,3367
75
75
  tinybird/tb_cli_modules/regions.py,sha256=QjsL5H6Kg-qr0aYVLrvb1STeJ5Sx_sjvbOYO0LrEGMk,166
76
76
  tinybird/tb_cli_modules/telemetry.py,sha256=iEGnMuCuNhvF6ln__j6X9MSTwL_0Hm-GgFHHHvhfknk,10466
77
- tinybird-0.0.1.dev61.dist-info/METADATA,sha256=2DnZbQC6aEzXMKMLff8KgszlSLd9r9HhEI3MsNcLczM,2482
78
- tinybird-0.0.1.dev61.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
79
- tinybird-0.0.1.dev61.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
80
- tinybird-0.0.1.dev61.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
81
- tinybird-0.0.1.dev61.dist-info/RECORD,,
77
+ tinybird-0.0.1.dev62.dist-info/METADATA,sha256=TSfflXA3BB3Bmp-J9OHaPfaXsq4ft7QlDsFiRbpBmVI,2482
78
+ tinybird-0.0.1.dev62.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
79
+ tinybird-0.0.1.dev62.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
80
+ tinybird-0.0.1.dev62.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
81
+ tinybird-0.0.1.dev62.dist-info/RECORD,,