tinybird 0.0.1.dev0__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/__cli__.py +8 -0
- tinybird/ch_utils/constants.py +244 -0
- tinybird/ch_utils/engine.py +855 -0
- tinybird/check_pypi.py +25 -0
- tinybird/client.py +1281 -0
- tinybird/config.py +117 -0
- tinybird/connectors.py +428 -0
- tinybird/context.py +23 -0
- tinybird/datafile.py +5589 -0
- tinybird/datatypes.py +434 -0
- tinybird/feedback_manager.py +1022 -0
- tinybird/git_settings.py +145 -0
- tinybird/sql.py +865 -0
- tinybird/sql_template.py +2343 -0
- tinybird/sql_template_fmt.py +281 -0
- tinybird/sql_toolset.py +350 -0
- tinybird/syncasync.py +682 -0
- tinybird/tb_cli.py +25 -0
- tinybird/tb_cli_modules/auth.py +252 -0
- tinybird/tb_cli_modules/branch.py +1043 -0
- tinybird/tb_cli_modules/cicd.py +434 -0
- tinybird/tb_cli_modules/cli.py +1571 -0
- tinybird/tb_cli_modules/common.py +2082 -0
- tinybird/tb_cli_modules/config.py +344 -0
- tinybird/tb_cli_modules/connection.py +803 -0
- tinybird/tb_cli_modules/datasource.py +900 -0
- tinybird/tb_cli_modules/exceptions.py +91 -0
- tinybird/tb_cli_modules/fmt.py +91 -0
- tinybird/tb_cli_modules/job.py +85 -0
- tinybird/tb_cli_modules/pipe.py +858 -0
- tinybird/tb_cli_modules/regions.py +9 -0
- tinybird/tb_cli_modules/tag.py +100 -0
- tinybird/tb_cli_modules/telemetry.py +310 -0
- tinybird/tb_cli_modules/test.py +107 -0
- tinybird/tb_cli_modules/tinyunit/tinyunit.py +340 -0
- tinybird/tb_cli_modules/tinyunit/tinyunit_lib.py +71 -0
- tinybird/tb_cli_modules/token.py +349 -0
- tinybird/tb_cli_modules/workspace.py +269 -0
- tinybird/tb_cli_modules/workspace_members.py +212 -0
- tinybird/tornado_template.py +1194 -0
- tinybird-0.0.1.dev0.dist-info/METADATA +2815 -0
- tinybird-0.0.1.dev0.dist-info/RECORD +45 -0
- tinybird-0.0.1.dev0.dist-info/WHEEL +5 -0
- tinybird-0.0.1.dev0.dist-info/entry_points.txt +2 -0
- tinybird-0.0.1.dev0.dist-info/top_level.txt +4 -0
tinybird/tb_cli.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
if sys.platform == "win32":
|
|
5
|
+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
|
6
|
+
|
|
7
|
+
import tinybird.tb_cli_modules.auth
|
|
8
|
+
import tinybird.tb_cli_modules.branch
|
|
9
|
+
import tinybird.tb_cli_modules.cli
|
|
10
|
+
import tinybird.tb_cli_modules.common
|
|
11
|
+
import tinybird.tb_cli_modules.connection
|
|
12
|
+
import tinybird.tb_cli_modules.datasource
|
|
13
|
+
import tinybird.tb_cli_modules.fmt
|
|
14
|
+
import tinybird.tb_cli_modules.job
|
|
15
|
+
import tinybird.tb_cli_modules.pipe
|
|
16
|
+
import tinybird.tb_cli_modules.tag
|
|
17
|
+
import tinybird.tb_cli_modules.test
|
|
18
|
+
import tinybird.tb_cli_modules.token
|
|
19
|
+
import tinybird.tb_cli_modules.workspace
|
|
20
|
+
import tinybird.tb_cli_modules.workspace_members
|
|
21
|
+
|
|
22
|
+
cli = tinybird.tb_cli_modules.cli.cli
|
|
23
|
+
|
|
24
|
+
if __name__ == "__main__":
|
|
25
|
+
cli()
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
# This is a command file for our CLI. Please keep it clean.
|
|
2
|
+
#
|
|
3
|
+
# - If it makes sense and only when strictly necessary, you can create utility functions in this file.
|
|
4
|
+
# - But please, **do not** interleave utility functions and command definitions.
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
from typing import Any, Dict, List, Optional
|
|
8
|
+
|
|
9
|
+
import click
|
|
10
|
+
import humanfriendly.tables
|
|
11
|
+
|
|
12
|
+
from tinybird.config import get_display_host
|
|
13
|
+
from tinybird.feedback_manager import FeedbackManager
|
|
14
|
+
from tinybird.tb_cli_modules.cli import cli
|
|
15
|
+
from tinybird.tb_cli_modules.common import (
|
|
16
|
+
configure_connector,
|
|
17
|
+
coro,
|
|
18
|
+
echo_safe_humanfriendly_tables_format_smart_table,
|
|
19
|
+
get_host_from_region,
|
|
20
|
+
get_regions,
|
|
21
|
+
try_authenticate,
|
|
22
|
+
try_update_config_with_remote,
|
|
23
|
+
)
|
|
24
|
+
from tinybird.tb_cli_modules.config import CLIConfig, ConfigValueOrigin
|
|
25
|
+
from tinybird.tb_cli_modules.exceptions import CLIAuthException
|
|
26
|
+
from tinybird.tb_cli_modules.regions import Region
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@cli.group(invoke_without_command=True)
|
|
30
|
+
@click.option("--token", help="Use auth token, defaults to TB_TOKEN envvar, then to the .tinyb file")
|
|
31
|
+
@click.option(
|
|
32
|
+
"--host",
|
|
33
|
+
help="Set custom host if it's different than https://api.tinybird.co. Check https://www.tinybird.co/docs/api-reference/overview#regions-and-endpoints for the available list of regions",
|
|
34
|
+
)
|
|
35
|
+
@click.option(
|
|
36
|
+
"--region", envvar="TB_REGION", help="Set region. Run 'tb auth ls' to show available regions. Overrides host."
|
|
37
|
+
)
|
|
38
|
+
@click.option(
|
|
39
|
+
"--connector",
|
|
40
|
+
type=click.Choice(["bigquery", "snowflake"], case_sensitive=True),
|
|
41
|
+
help="Set credentials for one of the supported connectors",
|
|
42
|
+
)
|
|
43
|
+
@click.option(
|
|
44
|
+
"-i",
|
|
45
|
+
"--interactive",
|
|
46
|
+
is_flag=True,
|
|
47
|
+
default=False,
|
|
48
|
+
help="Show available regions and select where to authenticate to",
|
|
49
|
+
)
|
|
50
|
+
@click.pass_context
|
|
51
|
+
@coro
|
|
52
|
+
async def auth(ctx: click.Context, token: str, host: str, region: str, connector: str, interactive: bool) -> None:
|
|
53
|
+
"""Configure auth."""
|
|
54
|
+
|
|
55
|
+
config: CLIConfig = CLIConfig.get_project_config()
|
|
56
|
+
if token:
|
|
57
|
+
config.set_token(token)
|
|
58
|
+
if host:
|
|
59
|
+
config.set_host(host)
|
|
60
|
+
|
|
61
|
+
if connector:
|
|
62
|
+
await configure_connector(connector)
|
|
63
|
+
return
|
|
64
|
+
|
|
65
|
+
# Only run when doing a bare 'tb auth'
|
|
66
|
+
if ctx.invoked_subcommand:
|
|
67
|
+
return
|
|
68
|
+
|
|
69
|
+
assert isinstance(ctx.parent, click.Context)
|
|
70
|
+
|
|
71
|
+
env_token = os.environ.get("TB_TOKEN", None)
|
|
72
|
+
|
|
73
|
+
# If no token passed, let's clear the current one to
|
|
74
|
+
# do a clean auth
|
|
75
|
+
if not token and not ctx.parent.params.get("token") and not env_token:
|
|
76
|
+
config.set_token(None)
|
|
77
|
+
else:
|
|
78
|
+
if env_token and not token:
|
|
79
|
+
click.echo(FeedbackManager.info_reading_from_env(value="token", envvar="TB_TOKEN"))
|
|
80
|
+
|
|
81
|
+
regions: Optional[List[Region]] = None
|
|
82
|
+
try_all_regions = True
|
|
83
|
+
|
|
84
|
+
if host:
|
|
85
|
+
try_all_regions = False
|
|
86
|
+
|
|
87
|
+
if region:
|
|
88
|
+
regions, host = await get_host_from_region(config, region, config.get_host())
|
|
89
|
+
config.set_host(host)
|
|
90
|
+
if token:
|
|
91
|
+
config.set_token_for_host(token, host)
|
|
92
|
+
try_all_regions = False
|
|
93
|
+
|
|
94
|
+
if not await try_authenticate(config, regions=regions, interactive=interactive, try_all_regions=try_all_regions):
|
|
95
|
+
raise CLIAuthException(FeedbackManager.error_invalid_token_for_host(host=config.get_host()))
|
|
96
|
+
|
|
97
|
+
config.persist_to_file()
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@auth.command(name="login", hidden=True)
|
|
101
|
+
@click.option(
|
|
102
|
+
"--host",
|
|
103
|
+
help="Set custom host if it's different than https://api.tinybird.co. Use `tb auth ls` or check https://docs.tinybird.co/cli.html for the available list of regions.",
|
|
104
|
+
)
|
|
105
|
+
@click.argument("token", required=False)
|
|
106
|
+
@coro
|
|
107
|
+
async def auth_login(host: Optional[str], token: Optional[str]) -> None:
|
|
108
|
+
"""Authenticate with a Tinybird host.
|
|
109
|
+
|
|
110
|
+
The authentication mode is token based. After completion, the authentication token
|
|
111
|
+
will be stored internally.
|
|
112
|
+
|
|
113
|
+
You need your User Token to log into Tinybird. Please, check the docs at
|
|
114
|
+
https://www.tinybird.co/docs/concepts/auth-tokens.html for more info.
|
|
115
|
+
|
|
116
|
+
Alternatively, tb will use the authentication token found in the environment
|
|
117
|
+
variable TB_USER_TOKEN. This method is most suitable for "headless" use of tb
|
|
118
|
+
such as in automations or in a CI environment."""
|
|
119
|
+
config = CLIConfig.get_global_config()
|
|
120
|
+
|
|
121
|
+
if host:
|
|
122
|
+
config.set_host(host)
|
|
123
|
+
|
|
124
|
+
if not token:
|
|
125
|
+
click.echo(FeedbackManager.info_pre_prompt_auth_login_user_token(host=config.get_host()))
|
|
126
|
+
token = click.prompt(FeedbackManager.prompt_auth_login_user_token(), type=str, hide_input=True)
|
|
127
|
+
if not token:
|
|
128
|
+
raise CLIAuthException(FeedbackManager.error_auth_login_token_expected())
|
|
129
|
+
config.set_user_token(token)
|
|
130
|
+
|
|
131
|
+
auth_info: Dict[str, Any] = await config.get_user_client().check_auth_login()
|
|
132
|
+
if not auth_info.get("is_valid", False):
|
|
133
|
+
raise CLIAuthException(FeedbackManager.error_auth_login_not_valid(host=config.get_host()))
|
|
134
|
+
|
|
135
|
+
if not auth_info.get("is_user", False):
|
|
136
|
+
raise CLIAuthException(FeedbackManager.error_auth_login_not_user(host=config.get_host()))
|
|
137
|
+
|
|
138
|
+
config.persist_to_file()
|
|
139
|
+
|
|
140
|
+
# No more output needed as per "The art of UNIX programming"
|
|
141
|
+
# http://www.catb.org/~esr/writings/taoup/html/ch11s09.html
|
|
142
|
+
# > be chatty only about things that deviate from what's normally expected.
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
@auth.command(name="logout", hidden=True)
|
|
146
|
+
@coro
|
|
147
|
+
async def auth_logout() -> None:
|
|
148
|
+
"""Remove authentication from Tinybird."""
|
|
149
|
+
conf = CLIConfig.get_global_config()
|
|
150
|
+
conf.set_user_token(None)
|
|
151
|
+
conf.persist_to_file()
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
@auth.command(name="info")
|
|
155
|
+
@coro
|
|
156
|
+
async def auth_info() -> None:
|
|
157
|
+
"""Get information about the authentication that is currently being used"""
|
|
158
|
+
|
|
159
|
+
config = CLIConfig.get_project_config()
|
|
160
|
+
_ = await try_update_config_with_remote(config, raise_on_errors=False)
|
|
161
|
+
|
|
162
|
+
if "id" in config:
|
|
163
|
+
table = []
|
|
164
|
+
user_email = config.get("user_email", "No user")
|
|
165
|
+
|
|
166
|
+
ORIGINS: Dict[ConfigValueOrigin, str] = {
|
|
167
|
+
ConfigValueOrigin.CONFIG: ".tinyb",
|
|
168
|
+
ConfigValueOrigin.DEFAULT: ".tinyb",
|
|
169
|
+
ConfigValueOrigin.ENVIRONMENT: "env",
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
token_origin = ORIGINS.get(config.get_value_origin("token"), "")
|
|
173
|
+
token = f"{config.get_token()} ({token_origin})"
|
|
174
|
+
|
|
175
|
+
host = config.get("host") or ""
|
|
176
|
+
ui_host = get_display_host(host)
|
|
177
|
+
|
|
178
|
+
if config.get_user_token():
|
|
179
|
+
user_token_origin = ORIGINS.get(config.get_value_origin("user_token"), "")
|
|
180
|
+
user_token = f"{config.get_user_token()} ({user_token_origin})"
|
|
181
|
+
columns = ["user", "user_token", "token", "host", "ui", "workspace_name", "workspace_id"]
|
|
182
|
+
table.append([user_email, user_token, token, host, ui_host, config["name"], config["id"]])
|
|
183
|
+
else:
|
|
184
|
+
columns = ["user", "token", "host", "ui", "workspace_name", "workspace_id"]
|
|
185
|
+
table.append([user_email, token, host, ui_host, config["name"], config["id"]])
|
|
186
|
+
|
|
187
|
+
click.echo(humanfriendly.tables.format_robust_table(table, column_names=columns))
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
@auth.command(name="ls")
|
|
191
|
+
@coro
|
|
192
|
+
async def auth_ls() -> None:
|
|
193
|
+
"""List available regions to authenticate."""
|
|
194
|
+
|
|
195
|
+
click.echo(FeedbackManager.info_available_regions())
|
|
196
|
+
|
|
197
|
+
config = CLIConfig.get_project_config()
|
|
198
|
+
_ = await try_update_config_with_remote(config, raise_on_errors=False)
|
|
199
|
+
|
|
200
|
+
table: List[List[Any]] = []
|
|
201
|
+
regions: List[Region] = await get_regions(config)
|
|
202
|
+
if regions:
|
|
203
|
+
|
|
204
|
+
def is_current(region: Region) -> bool:
|
|
205
|
+
return region["host"] == config.get("host") or region["api_host"] == config.get("host")
|
|
206
|
+
|
|
207
|
+
for index, region in enumerate(regions):
|
|
208
|
+
table.append(
|
|
209
|
+
[
|
|
210
|
+
index + 1,
|
|
211
|
+
region["name"].lower(),
|
|
212
|
+
region.get("provider") or "",
|
|
213
|
+
region["host"],
|
|
214
|
+
region["api_host"],
|
|
215
|
+
is_current(region),
|
|
216
|
+
]
|
|
217
|
+
)
|
|
218
|
+
else:
|
|
219
|
+
table.append([1, "default", "", config["host"], True])
|
|
220
|
+
|
|
221
|
+
columns: List[str] = ["idx", "region", "provider", "ui", "host", "current"]
|
|
222
|
+
echo_safe_humanfriendly_tables_format_smart_table(table, column_names=columns)
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
@auth.command(name="use")
|
|
226
|
+
@click.argument("region_name_or_host_or_id")
|
|
227
|
+
@coro
|
|
228
|
+
async def auth_use(region_name_or_host_or_id: str) -> None:
|
|
229
|
+
"""Switch to a different region.
|
|
230
|
+
You can pass the region name, the region host url, or the region index
|
|
231
|
+
after listing available regions with 'tb auth ls'
|
|
232
|
+
|
|
233
|
+
\b
|
|
234
|
+
Example usage:
|
|
235
|
+
\b
|
|
236
|
+
$ tb auth use us-east
|
|
237
|
+
$ tb auth use 1
|
|
238
|
+
$ tb auth use https://ui.us-east.tinybird.co
|
|
239
|
+
"""
|
|
240
|
+
|
|
241
|
+
config = CLIConfig.get_project_config()
|
|
242
|
+
_ = await try_update_config_with_remote(config, raise_on_errors=False)
|
|
243
|
+
|
|
244
|
+
regions, host = await get_host_from_region(config, region_name_or_host_or_id, config.get_host())
|
|
245
|
+
config.set_host(host)
|
|
246
|
+
|
|
247
|
+
if not await try_authenticate(config, regions):
|
|
248
|
+
msg = FeedbackManager.error_wrong_config_file(config_file=config._path)
|
|
249
|
+
raise CLIAuthException(msg)
|
|
250
|
+
|
|
251
|
+
config.persist_to_file()
|
|
252
|
+
click.echo(FeedbackManager.success_now_using_config(name=config["name"], id=config["id"]))
|