tinybird 0.0.1.dev296__py3-none-any.whl → 0.0.1.dev298__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/forward/commands'
5
5
  __author__ = 'Tinybird'
6
6
  __author_email__ = 'support@tinybird.co'
7
- __version__ = '0.0.1.dev296'
8
- __revision__ = 'b2373b7'
7
+ __version__ = '0.0.1.dev298'
8
+ __revision__ = '86d8c44'
tinybird/tb/config.py CHANGED
@@ -40,6 +40,23 @@ CLOUD_HOSTS = {
40
40
  "https://ui.europe-west2.gcp.tinybird.co": "https://cloud.tinybird.co/gcp/europe-west2",
41
41
  }
42
42
 
43
+ CH_HOSTS = {
44
+ "https://api.tinybird.co": "https://clickhouse.tinybird.co",
45
+ "https://api.us-east.tinybird.co": "https://clickhouse.us-east.tinybird.co",
46
+ "https://api.us-east.aws.tinybird.co": "https://clickhouse.us-east-1.aws.tinybird.co",
47
+ "https://api.us-west-2.aws.tinybird.co": "https://clickhouse.us-west-2.aws.tinybird.co",
48
+ "https://api.eu-central-1.aws.tinybird.co": "https://clickhouse.eu-central-1.aws.tinybird.co",
49
+ "https://api.eu-west-1.aws.tinybird.co": "https://clickhouse.eu-west-1.aws.tinybird.co",
50
+ "https://api.europe-west2.gcp.tinybird.co": "https://clickhouse.europe-west2.gcp.tinybird.co",
51
+ "https://api.ap-east.aws.tinybird.co": "https://clickhouse.ap-east.aws.tinybird.co",
52
+ "https://ui.tinybird.co": "https://clickhouse.tinybird.co",
53
+ "https://ui.us-east.tinybird.co": "https://clickhouse.us-east.tinybird.co",
54
+ "https://ui.us-east.aws.tinybird.co": "https://clickhouse.us-east.aws.tinybird.co",
55
+ "https://ui.us-west-2.aws.tinybird.co": "https://clickhouse.us-west-2.aws.tinybird.co",
56
+ "https://ui.eu-central-1.aws.tinybird.co": "https://clickhouse.eu-central-1.aws.tinybird.co",
57
+ "https://ui.europe-west2.gcp.tinybird.co": "https://clickhouse.europe-west2.gcp.tinybird.co",
58
+ }
59
+
43
60
 
44
61
  def get_config(
45
62
  host: Optional[str], token: Optional[str], semver: Optional[str] = None, config_file: Optional[str] = None
@@ -85,6 +102,13 @@ def get_display_cloud_host(api_host: str) -> str:
85
102
  return CLOUD_HOSTS.get(api_host, api_host)
86
103
 
87
104
 
105
+ def get_clickhouse_host(api_host: str) -> str:
106
+ is_local = "localhost" in api_host
107
+ if is_local:
108
+ return "http://localhost:7182"
109
+ return f"{CH_HOSTS.get(api_host, api_host.replace('api.', 'clickhouse.'))}:443"
110
+
111
+
88
112
  class FeatureFlags:
89
113
  @classmethod
90
114
  def ignore_sql_errors(cls) -> bool: # Context: #1155
@@ -17,7 +17,7 @@ from requests import Response
17
17
 
18
18
  from tinybird.tb.check_pypi import CheckPypi
19
19
  from tinybird.tb.client import TinyB
20
- from tinybird.tb.config import CURRENT_VERSION, get_display_cloud_host
20
+ from tinybird.tb.config import CURRENT_VERSION, get_clickhouse_host, get_display_cloud_host
21
21
  from tinybird.tb.modules.agent.animations import ThinkingAnimation
22
22
  from tinybird.tb.modules.agent.banner import display_banner
23
23
  from tinybird.tb.modules.agent.command_agent import CommandAgent
@@ -284,7 +284,14 @@ class TinybirdAgent:
284
284
  - API Host: {ctx.deps.local_host}
285
285
  - Token: {ctx.deps.local_token}
286
286
  - UI Dashboard URL: {get_display_cloud_host(ctx.deps.local_host)}/{ctx.deps.workspace_name}
287
- """
287
+ - ClickHouse native HTTP interface:
288
+ - Protocol: HTTP
289
+ - Host: localhost
290
+ - Port: 7182
291
+ - Full URL: http://localhost:7182
292
+ - Username: {ctx.deps.workspace_name} # Optional, for identification purposes
293
+ - Password: __TB_CLOUD_TOKEN__ # Your Tinybird auth token
294
+ """
288
295
 
289
296
  @self.agent.instructions
290
297
  def get_cloud_host(ctx: RunContext[TinybirdAgentContext]) -> str:
@@ -302,6 +309,7 @@ class TinybirdAgent:
302
309
 
303
310
  region_provider = region["provider"]
304
311
  region_name = region["name"]
312
+ ch_host = get_clickhouse_host(ctx.deps.host)
305
313
  return f"""
306
314
  # Tinybird Cloud info (region details):
307
315
  - API Host: {ctx.deps.host}
@@ -310,6 +318,14 @@ class TinybirdAgent:
310
318
  - Region provider: {region_provider}
311
319
  - Region name: {region_name}
312
320
  - UI Dashboard URL: {get_display_cloud_host(ctx.deps.host)}/{ctx.deps.workspace_name}
321
+ - ClickHouse native HTTP interface:
322
+ - Protocol: HTTPS
323
+ - Host: {ch_host.replace("https://", "").replace(":443", "")}
324
+ - Port: 443 (HTTPS)
325
+ - SSL/TLS: Required (enabled)
326
+ - Full URL: {ch_host}
327
+ - Username: {ctx.deps.workspace_name} # Optional, for identification purposes
328
+ - Password: __TB_CLOUD_TOKEN__ # Your Tinybird auth token
313
329
  """
314
330
 
315
331
  @self.agent.instructions
@@ -2,7 +2,6 @@
2
2
  #
3
3
  # - If it makes sense and only when strictly necessary, you can create utility functions in this file.
4
4
  # - But please, **do not** interleave utility functions and command definitions.
5
-
6
5
  import json
7
6
  import logging
8
7
  import os
@@ -11,9 +10,11 @@ import sys
11
10
  from os import environ, getcwd
12
11
  from pathlib import Path
13
12
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union
13
+ from urllib.parse import urlencode
14
14
 
15
15
  import click
16
16
  import humanfriendly
17
+ import requests
17
18
  from click import Context
18
19
 
19
20
  from tinybird.tb import __cli__
@@ -21,7 +22,9 @@ from tinybird.tb.check_pypi import CheckPypi
21
22
  from tinybird.tb.client import (
22
23
  AuthException,
23
24
  AuthNoTokenException,
25
+ TinyB,
24
26
  )
27
+ from tinybird.tb.config import get_clickhouse_host
25
28
  from tinybird.tb.modules.agent import run_agent
26
29
  from tinybird.tb.modules.common import (
27
30
  CatchAuthExceptions,
@@ -36,6 +39,7 @@ from tinybird.tb.modules.common import (
36
39
  from tinybird.tb.modules.config import CURRENT_VERSION, CLIConfig
37
40
  from tinybird.tb.modules.datafile.build import build_graph
38
41
  from tinybird.tb.modules.datafile.pull import folder_pull
42
+ from tinybird.tb.modules.exceptions import CLIChException
39
43
  from tinybird.tb.modules.feedback_manager import FeedbackManager
40
44
  from tinybird.tb.modules.local_common import get_tinybird_local_client
41
45
  from tinybird.tb.modules.project import Project
@@ -336,6 +340,88 @@ def sql(
336
340
  click.echo(FeedbackManager.info_no_rows())
337
341
 
338
342
 
343
+ @cli.command(
344
+ name="ch",
345
+ context_settings=dict(
346
+ ignore_unknown_options=True,
347
+ allow_extra_args=True,
348
+ ),
349
+ )
350
+ @click.option(
351
+ "--query",
352
+ type=str,
353
+ default=None,
354
+ required=False,
355
+ help="The query to run against ClickHouse.",
356
+ )
357
+ @click.option(
358
+ "--user",
359
+ required=False,
360
+ help="User field is not used for authentication but helps identify the connection.",
361
+ )
362
+ @click.option(
363
+ "--password",
364
+ required=False,
365
+ help="Your Tinybird Auth Token. If not provided, the token will be your current workspace token.",
366
+ )
367
+ @click.option(
368
+ "-m",
369
+ "--multiline",
370
+ is_flag=True,
371
+ default=False,
372
+ help="Enable multiline mode - read the query from multiple lines until a semicolon.",
373
+ )
374
+ @click.pass_context
375
+ def ch(ctx: Context, query: str, user: Optional[str], password: Optional[str], multiline: bool) -> None:
376
+ """Run a query against ClickHouse native HTTP interface."""
377
+ try:
378
+ query_arg = next((arg for arg in ctx.args if not arg.startswith("--param_")), None)
379
+ if query_arg and not query:
380
+ query = query_arg
381
+
382
+ if not query and not sys.stdin.isatty(): # Check if there's piped input
383
+ query = sys.stdin.read().strip()
384
+
385
+ if not query:
386
+ click.echo(FeedbackManager.warning(message="Nothing to do. No query provided"))
387
+ return
388
+
389
+ if multiline:
390
+ queries = [query.strip() for query in query.split(";") if query.strip()]
391
+ else:
392
+ queries = [query]
393
+
394
+ client: TinyB = ctx.ensure_object(dict)["client"]
395
+ config = ctx.ensure_object(dict)["config"]
396
+ password = password or client.token
397
+ user = user or config.get("name", None)
398
+ ch_host = get_clickhouse_host(client.host)
399
+ headers = {"X-ClickHouse-Key": password}
400
+ if user:
401
+ headers["X-ClickHouse-User"] = user
402
+
403
+ params = {}
404
+
405
+ for param in ctx.args:
406
+ if param.startswith("--param_"):
407
+ param_name = param.split("=")[0].replace("--", "")
408
+ param_value = param.split("=")[1]
409
+ params[param_name] = param_value
410
+
411
+ for query in queries:
412
+ query_params = {**params, "query": query}
413
+ url = f"{ch_host}?{urlencode(query_params)}"
414
+ res = requests.get(url=url, headers=headers)
415
+
416
+ if res.status_code != 200:
417
+ raise Exception(res.text)
418
+
419
+ click.echo(res.text)
420
+
421
+ except Exception as e:
422
+ raise CLIChException(FeedbackManager.error(message=str(e)))
423
+
424
+
339
425
  def __patch_click_output():
340
426
  import re
341
427
 
@@ -146,3 +146,10 @@ class CLISecretException(CLIException):
146
146
 
147
147
  def __init__(self, message: str, **kw_telemetry_event_data: Any) -> None:
148
148
  super().__init__(message, "secret_error", **kw_telemetry_event_data)
149
+
150
+
151
+ class CLIChException(CLIException):
152
+ """Exceptions generated by the ch commands"""
153
+
154
+ def __init__(self, message: str, **kw_telemetry_event_data: Any) -> None:
155
+ super().__init__(message, "ch_error", **kw_telemetry_event_data)
@@ -4,7 +4,7 @@ from typing import Any, Dict, Iterable, List, Optional, Tuple
4
4
  import click
5
5
 
6
6
  from tinybird.tb.client import TinyB
7
- from tinybird.tb.config import get_display_cloud_host
7
+ from tinybird.tb.config import get_clickhouse_host, get_display_cloud_host
8
8
  from tinybird.tb.modules.cli import CLIConfig, cli
9
9
  from tinybird.tb.modules.common import echo_json, force_echo, format_robust_table
10
10
  from tinybird.tb.modules.exceptions import CLILocalException
@@ -54,9 +54,10 @@ def get_cloud_info(ctx_config: Dict[str, Any]) -> Tuple[Iterable[Any], List[str]
54
54
  token = config.get_token() or "No workspace token found"
55
55
  api_host = config.get("host") or "No API host found"
56
56
  ui_host = get_display_cloud_host(api_host)
57
+ ch_host = get_clickhouse_host(api_host)
57
58
  user_email = config.get("user_email") or "No user email found"
58
59
  user_token = config.get_user_token() or "No user token found"
59
- return get_env_info(client, ctx_config, user_email, token, user_token, api_host, ui_host)
60
+ return get_env_info(client, ctx_config, user_email, token, user_token, api_host, ui_host, ch_host)
60
61
  except Exception:
61
62
  click.echo(
62
63
  FeedbackManager.warning(
@@ -75,7 +76,10 @@ def get_local_info(config: Dict[str, Any]) -> Tuple[Iterable[Any], List[str]]:
75
76
  user_token = local_config.get_user_token() or "No user token found"
76
77
  api_host = TB_LOCAL_ADDRESS
77
78
  ui_host = get_display_cloud_host(api_host)
78
- return get_env_info(local_client, config, user_email, token, user_token, api_host, ui_host, is_local=True)
79
+ ch_host = get_clickhouse_host(api_host)
80
+ return get_env_info(
81
+ local_client, config, user_email, token, user_token, api_host, ui_host, ch_host, is_local=True
82
+ )
79
83
  except CLILocalException as e:
80
84
  raise e
81
85
  except Exception as e:
@@ -95,6 +99,7 @@ def get_env_info(
95
99
  user_token: str,
96
100
  api_host: str,
97
101
  ui_host: str,
102
+ ch_host: str,
98
103
  is_local=False,
99
104
  ) -> Tuple[List[Any], List[str]]:
100
105
  user_workspaces = client.user_workspaces(version="v1")
@@ -115,11 +120,20 @@ def get_env_info(
115
120
 
116
121
  assert isinstance(current_main_workspace, dict)
117
122
 
118
- columns = ["user", "workspace_name", "workspace_id", "token", "user_token", "api", "ui"]
123
+ columns = ["user", "workspace_name", "workspace_id", "token", "user_token", "api", "ui", "clickhouse"]
119
124
  if current_main_workspace["name"]:
120
125
  ui_host += f"/{current_main_workspace['name']}"
121
126
  table = [
122
- (user_email, current_main_workspace["name"], current_main_workspace["id"], token, user_token, api_host, ui_host)
127
+ (
128
+ user_email,
129
+ current_main_workspace["name"],
130
+ current_main_workspace["id"],
131
+ token,
132
+ user_token,
133
+ api_host,
134
+ ui_host,
135
+ ch_host,
136
+ )
123
137
  ]
124
138
 
125
139
  if is_local and (
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: tinybird
3
- Version: 0.0.1.dev296
3
+ Version: 0.0.1.dev298
4
4
  Summary: Tinybird Command Line Tool
5
5
  Home-page: https://www.tinybird.co/docs/forward/commands
6
6
  Author: Tinybird
@@ -18,15 +18,15 @@ tinybird/datafile/exceptions.py,sha256=8rw2umdZjtby85QbuRKFO5ETz_eRHwUY5l7eHsy1w
18
18
  tinybird/datafile/parse_connection.py,sha256=tRyn2Rpr1TeWet5BXmMoQgaotbGdYep1qiTak_OqC5E,1825
19
19
  tinybird/datafile/parse_datasource.py,sha256=ssW8QeFSgglVFi3sDZj_HgkJiTJ2069v2JgqnH3CkDE,1825
20
20
  tinybird/datafile/parse_pipe.py,sha256=8e9LMecSQVWHC4AXf8cdxoQ1nxUR4fTObYxTctO_EXQ,3816
21
- tinybird/tb/__cli__.py,sha256=P2Ti-wEFHoOSwUBJ94hsFL-3YXmkiScFvoAVUOKFdZw,247
21
+ tinybird/tb/__cli__.py,sha256=aaMYA_yViuQ3_sWIbTc05asZRA5XLCXYtGIr441EDtc,247
22
22
  tinybird/tb/check_pypi.py,sha256=Gp0HkHHDFMSDL6nxKlOY51z7z1Uv-2LRexNTZSHHGmM,552
23
23
  tinybird/tb/cli.py,sha256=FdDFEIayjmsZEVsVSSvRiVYn_FHOVg_zWQzchnzfWho,1008
24
24
  tinybird/tb/client.py,sha256=IQRaInDjOwr9Fzaz3_xXc3aUGqh94tM2lew7IZbB9eM,53733
25
- tinybird/tb/config.py,sha256=mhMTGnMB5KcxGoh3dewIr2Jjsa6pHE183gCPAQWyp6o,3973
25
+ tinybird/tb/config.py,sha256=XIKju3xxpo40oQ48zDtSv0vgUrBZBHSmHJi4SHksjXE,5447
26
26
  tinybird/tb/modules/build.py,sha256=vyhQyyDGLUHrJGdKoRy0gCc62vzZrRjtyzdXAJttYE4,7925
27
27
  tinybird/tb/modules/build_common.py,sha256=w6UUXfr73EKjTCBqKgZxciMoL8HVwpg37gL4GXYKycw,20201
28
28
  tinybird/tb/modules/cicd.py,sha256=0KLKccha9IP749QvlXBmzdWv1On3mFwMY4DUcJlBxiE,7326
29
- tinybird/tb/modules/cli.py,sha256=-hkwg2ZIWPtldkLkgdY7RYWacOJtkMx58eqqYzMoMfw,17793
29
+ tinybird/tb/modules/cli.py,sha256=6mNZVIc2RmINZxagAxUJ06iPgkmiX2P4cD9W2gIhyFs,20513
30
30
  tinybird/tb/modules/common.py,sha256=zY0PFDQVWjhu2MivBtUmcXtAlv7imgO-RG_PUK37XvI,83659
31
31
  tinybird/tb/modules/config.py,sha256=gK7rgaWTDd4ZKCrNEg_Uemr26EQjqWt6TjyQKujxOws,11462
32
32
  tinybird/tb/modules/connection.py,sha256=axp8Fny1_4PSLJGN4UF6WygyRbQtM3Lbt6thxHKTxzw,17790
@@ -38,9 +38,9 @@ tinybird/tb/modules/deployment_common.py,sha256=ZX27oUw7u1ld20qiXH69j7m0DImOc5nc
38
38
  tinybird/tb/modules/deprecations.py,sha256=rrszC1f_JJeJ8mUxGoCxckQTJFBCR8wREf4XXXN-PRc,4507
39
39
  tinybird/tb/modules/dev_server.py,sha256=57FCKuWpErwYUYgHspYDkLWEm9F4pbvVOtMrFXX1fVU,10129
40
40
  tinybird/tb/modules/endpoint.py,sha256=ksRj6mfDb9Xv63PhTkV_uKSosgysHElqagg3RTt21Do,11958
41
- tinybird/tb/modules/exceptions.py,sha256=KEj3E-zN7Z28igvptlngXIjlHR9vAJk59Vs4zpwm4vA,5469
41
+ tinybird/tb/modules/exceptions.py,sha256=HVBTNcHKSiE934upo4qNImV9jvctCuqqxVqIM1vEdus,5709
42
42
  tinybird/tb/modules/feedback_manager.py,sha256=duigLI2UIeMzP5IOa7XUty23NRvNssm2ZAKicuun3Pg,78130
43
- tinybird/tb/modules/info.py,sha256=F5vY4kHS_kyO2uSBKac92HoOb447oDeRlzpwtAHTuKc,6872
43
+ tinybird/tb/modules/info.py,sha256=UKlazKWSE3bzEtggTwyDhmkh7WRrWURuBraR36ClbmQ,7177
44
44
  tinybird/tb/modules/infra.py,sha256=JE9oLIyF4bi_JBoe-BgZ5HhKp_lQgSihuSV1KIS02Qs,32709
45
45
  tinybird/tb/modules/job.py,sha256=wBsnu8UPTOha2rkLvucgmw4xYv73ubmui3eeSIF68ZM,3107
46
46
  tinybird/tb/modules/llm.py,sha256=fPBBCmM3KlCksLlgJkg4joDn6y3H5QjDzE-Pm4YNf7E,1782
@@ -70,7 +70,7 @@ tinybird/tb/modules/watch.py,sha256=R0wERRyL-PrwxKOLSk-T-EvkIczHpeoGirrl3JZxXa8,
70
70
  tinybird/tb/modules/workspace.py,sha256=tCP1zZMwBhLRGm22TGfpSd4cHvQLAS1o_azIXv_r6uw,11172
71
71
  tinybird/tb/modules/workspace_members.py,sha256=5JdkJgfuEwbq-t6vxkBhYwgsiTDxF790wsa6Xfif9nk,8608
72
72
  tinybird/tb/modules/agent/__init__.py,sha256=i3oe3vDIWWPaicdCM0zs7D7BJ1W0k7th93ooskHAV00,54
73
- tinybird/tb/modules/agent/agent.py,sha256=TqmXTsEGgt3rx6hPlRegCLdVxUzYF5P-x4OuOvIqFg0,37863
73
+ tinybird/tb/modules/agent/agent.py,sha256=mEm-GRhZAMHAfHc64udpEggbt1bQnqE6x151LT1_ECs,38579
74
74
  tinybird/tb/modules/agent/animations.py,sha256=4WOC5_2BracttmMCrV0H91tXfWcUzQHBUaIJc5FA7tE,3490
75
75
  tinybird/tb/modules/agent/banner.py,sha256=l6cO5Fi7lbVKp-GsBP8jf3IkjOWxg2jpAt9NBCy0WR8,4085
76
76
  tinybird/tb/modules/agent/command_agent.py,sha256=0Z08rQsir59zQAr-kkOvsKIFpIBsBSTGJJ1VgqqF5WA,3654
@@ -121,8 +121,8 @@ tinybird/tb_cli_modules/config.py,sha256=IsgdtFRnUrkY8-Zo32lmk6O7u3bHie1QCxLwgp4
121
121
  tinybird/tb_cli_modules/exceptions.py,sha256=pmucP4kTF4irIt7dXiG-FcnI-o3mvDusPmch1L8RCWk,3367
122
122
  tinybird/tb_cli_modules/regions.py,sha256=QjsL5H6Kg-qr0aYVLrvb1STeJ5Sx_sjvbOYO0LrEGMk,166
123
123
  tinybird/tb_cli_modules/telemetry.py,sha256=Hh2Io8ZPROSunbOLuMvuIFU4TqwWPmQTqal4WS09K1A,10449
124
- tinybird-0.0.1.dev296.dist-info/METADATA,sha256=QzTIE7fRrhXS5qTEMjtIHQHsbVBXOcPk8BwDp7NFZzA,1845
125
- tinybird-0.0.1.dev296.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
126
- tinybird-0.0.1.dev296.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
127
- tinybird-0.0.1.dev296.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
128
- tinybird-0.0.1.dev296.dist-info/RECORD,,
124
+ tinybird-0.0.1.dev298.dist-info/METADATA,sha256=xsci4KfsjjKP1GgGuwM6PMjF7knhRKTv4Ezmd4u6Rz8,1845
125
+ tinybird-0.0.1.dev298.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
126
+ tinybird-0.0.1.dev298.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
127
+ tinybird-0.0.1.dev298.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
128
+ tinybird-0.0.1.dev298.dist-info/RECORD,,