tinybird 0.0.1.dev182__py3-none-any.whl → 0.0.1.dev184__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.dev182'
8
- __revision__ = 'b1eeede'
7
+ __version__ = '0.0.1.dev184'
8
+ __revision__ = '0d5d2de'
@@ -3,8 +3,10 @@ import os
3
3
  import re
4
4
  from pathlib import Path
5
5
  from typing import Any, Dict, List, Optional
6
+ from urllib.parse import urlparse
6
7
 
7
8
  import click
9
+ import requests
8
10
 
9
11
  from tinybird.prompts import create_prompt, readme_prompt, rules_prompt
10
12
  from tinybird.tb.client import TinyB
@@ -25,7 +27,7 @@ from tinybird.tb.modules.project import Project
25
27
  @cli.command()
26
28
  @click.option(
27
29
  "--data",
28
- type=click.Path(exists=True),
30
+ type=str,
29
31
  default=None,
30
32
  help="Initial data to be used to create the project. Tinybird Local and authentication are required.",
31
33
  )
@@ -87,7 +89,10 @@ async def create(
87
89
 
88
90
  data_result: List[Path] = []
89
91
  if data:
90
- data_result = await create_resources_from_data(data, project, ctx_config)
92
+ if urlparse(data).scheme in ("http", "https"):
93
+ data_result = await create_resources_from_url(data, project, ctx_config)
94
+ else:
95
+ data_result = await create_resources_from_data(data, project, ctx_config)
91
96
  result.extend(data_result)
92
97
 
93
98
  prompt_result: List[Path] = []
@@ -134,14 +139,22 @@ async def create(
134
139
 
135
140
  if data:
136
141
  for ds_path in [ds for ds in data_result if ds.suffix == ".datasource"]:
137
- data_path = Path(data)
138
- data_content = data_path.read_text()
142
+ parsed_url = urlparse(data)
143
+ if parsed_url.scheme in ("http", "https"):
144
+ response = requests.get(data) # noqa: ASYNC210
145
+ data_content = response.text
146
+ data_format = parsed_url.path.split(".")[-1]
147
+ else:
148
+ data_path = Path(data)
149
+ data_content = data_path.read_text()
150
+ data_format = data_path.suffix.lstrip(".")
151
+
139
152
  ds_name = ds_path.stem
140
- data_format = data_path.suffix.lstrip(".")
141
153
  datasource_path = Path(folder) / "datasources" / f"{ds_name}.datasource"
142
- click.echo(FeedbackManager.info(message=f"✓ /fixtures/{ds_name}"))
154
+ click.echo(FeedbackManager.info(message=f"✓ /fixtures/{ds_name}.{data_format}"))
143
155
  persist_fixture(ds_name, data_content, folder, format=data_format)
144
156
  created_something = True
157
+
145
158
  elif prompt and prompt_result:
146
159
  ds_results = [path for path in prompt_result if path.suffix == ".datasource"]
147
160
  for datasource_path in ds_results:
@@ -452,8 +465,8 @@ async def create_resources_from_data(
452
465
  project: Project,
453
466
  config: Dict[str, Any],
454
467
  ) -> List[Path]:
455
- folder_path = project.path
456
468
  local_client = await get_tinybird_local_client(config)
469
+ folder_path = project.path
457
470
  path = folder_path / data
458
471
  result: List[Path] = []
459
472
  format = path.suffix.lstrip(".")
@@ -465,10 +478,33 @@ async def create_resources_from_data(
465
478
  pipe_file = generate_pipe_file(
466
479
  f"{name}_endpoint",
467
480
  f"""
468
- NODE endpoint
469
- SQL >
481
+ NODE endpoint
482
+ SQL >
483
+ SELECT * from {name}
484
+ TYPE ENDPOINT
485
+ """,
486
+ project.folder,
487
+ )
488
+ result.append(pipe_file)
489
+ return result
490
+
491
+
492
+ async def create_resources_from_url(url: str, project: Project, config: Dict[str, Any]) -> List[Path]:
493
+ result: List[Path] = []
494
+ local_client = await get_tinybird_local_client(config)
495
+ format = url.split(".")[-1]
496
+ ds_file = await _generate_datafile(url, local_client, format=format, force=True)
497
+ result.append(ds_file)
498
+ name = ds_file.stem
499
+ no_pipes = len(project.get_pipe_files()) == 0
500
+ if no_pipes:
501
+ pipe_file = generate_pipe_file(
502
+ f"{name}_endpoint",
503
+ f"""
504
+ NODE endpoint
505
+ SQL >
470
506
  SELECT * from {name}
471
- TYPE ENDPOINT
507
+ TYPE ENDPOINT
472
508
  """,
473
509
  project.folder,
474
510
  )
@@ -1,5 +1,5 @@
1
1
  from pathlib import Path
2
- from typing import Any, Dict, List, Union
2
+ from typing import Any, Dict, List, Optional, Union
3
3
 
4
4
  from tinybird.tb.modules.common import format_data_to_ndjson
5
5
 
@@ -17,10 +17,16 @@ def persist_fixture_sql(fixture_name: str, sql: str, folder: str) -> Path:
17
17
  return fixture_file
18
18
 
19
19
 
20
- def persist_fixture(fixture_name: str, data: Union[List[Dict[str, Any]], str], folder: str, format: str) -> Path:
21
- fixture_dir = get_fixture_dir(folder)
22
- fixture_file = fixture_dir / f"{fixture_name}.{format}"
23
- extension = f".{format}"
20
+ def persist_fixture(
21
+ fixture_name: str, data: Union[List[Dict[str, Any]], str], folder: str, format: str, target: Optional[str] = None
22
+ ) -> Path:
23
+ if target:
24
+ fixture_file = Path(target)
25
+ extension = fixture_file.suffix
26
+ else:
27
+ fixture_dir = get_fixture_dir(folder)
28
+ fixture_file = fixture_dir / f"{fixture_name}.{format}"
29
+ extension = f".{format}"
24
30
  if extension == FixtureExtension.NDJSON:
25
31
  fixture_file.write_text(data if isinstance(data, str) else format_data_to_ndjson(data))
26
32
  elif extension == FixtureExtension.CSV:
@@ -423,19 +423,15 @@ async def datasource_export(
423
423
  Example usage:
424
424
  - Export all rows as CSV: tb datasource export my_datasource
425
425
  - Export 1000 rows as NDJSON: tb datasource export my_datasource --format ndjson --rows 1000
426
- - Export to specific file: tb datasource export my_datasource --output ./data/export.csv
426
+ - Export to specific file: tb datasource export my_datasource --target ./data/export.csv
427
427
  """
428
428
  client: TinyB = ctx.ensure_object(dict)["client"]
429
429
  project: Project = ctx.ensure_object(dict)["project"]
430
430
 
431
- # Determine output filename if not provided
432
- if not target:
433
- target = f"{datasource}.{format_}"
434
-
435
431
  # Build query with optional row limit
436
432
  query = f"SELECT * FROM {datasource} WHERE {where or 1} LIMIT {rows}"
437
433
 
438
- click.echo(FeedbackManager.highlight(message=f"\n» Exporting {datasource} to {target}"))
434
+ click.echo(FeedbackManager.highlight(message=f"\n» Exporting {datasource}"))
439
435
 
440
436
  try:
441
437
  if format_ == "csv":
@@ -445,11 +441,13 @@ async def datasource_export(
445
441
 
446
442
  res = await client.query(query)
447
443
 
448
- fixture_path = persist_fixture(datasource, res, project.folder, format=format_)
449
- file_size = os.path.getsize(fixture_path)
444
+ target_path = persist_fixture(datasource, res, project.folder, format=format_, target=target)
445
+ file_size = os.path.getsize(target_path)
450
446
 
451
447
  click.echo(
452
- FeedbackManager.success(message=f"✓ Exported data to {target} ({humanfriendly.format_size(file_size)})")
448
+ FeedbackManager.success(
449
+ message=f"✓ Exported data to {str(target_path).replace(project.folder, '')} ({humanfriendly.format_size(file_size)})"
450
+ )
453
451
  )
454
452
 
455
453
  except Exception as e:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: tinybird
3
- Version: 0.0.1.dev182
3
+ Version: 0.0.1.dev184
4
4
  Summary: Tinybird Command Line Tool
5
5
  Home-page: https://www.tinybird.co/docs/forward/commands
6
6
  Author: Tinybird
@@ -12,7 +12,7 @@ tinybird/syncasync.py,sha256=IPnOx6lMbf9SNddN1eBtssg8vCLHMt76SuZ6YNYm-Yk,27761
12
12
  tinybird/tornado_template.py,sha256=jjNVDMnkYFWXflmT8KU_Ssbo5vR8KQq3EJMk5vYgXRw,41959
13
13
  tinybird/ch_utils/constants.py,sha256=aYvg2C_WxYWsnqPdZB1ZFoIr8ZY-XjUXYyHKE9Ansj0,3890
14
14
  tinybird/ch_utils/engine.py,sha256=X4tE9OrfaUy6kO9cqVEzyI9cDcmOF3IAssRRzsTsfEQ,40781
15
- tinybird/tb/__cli__.py,sha256=Hcpk55aD10v-3_hprG0jGUy2hJWHo_jTD4ohLxO7jIs,247
15
+ tinybird/tb/__cli__.py,sha256=53aFe84vyt7b02YzNl7TMyome7H2Q6p-1cvE7VbeusE,247
16
16
  tinybird/tb/check_pypi.py,sha256=rW4QmDRbtgKdUUwJCnBkVjmTjZSZGN-XgZhx7vMkC0w,1009
17
17
  tinybird/tb/cli.py,sha256=u3eGOhX0MHkuT6tiwaZ0_3twqLmqKXDAOxF7yV_Nn9Q,1075
18
18
  tinybird/tb/client.py,sha256=59GH0IoYSV_KUG0eEbDDYHSWH4OlkVnSRFXE3mYAM0s,56571
@@ -24,8 +24,8 @@ tinybird/tb/modules/common.py,sha256=lu1Z3VYImwocaHvqOW2FzBJP6F3Ev7RuXsItkCZ6jpo
24
24
  tinybird/tb/modules/config.py,sha256=ziqW_t_mRVvWOd85VoB4vKyvgMkEfpXDf9H4v38p2xc,11422
25
25
  tinybird/tb/modules/connection.py,sha256=7oOR7x4PhBcm1ETFFCH2YJ_3oeGXjAbmx1cnZX9_L70,9014
26
26
  tinybird/tb/modules/copy.py,sha256=2Mm4FWKehOG7CoOhiF1m9UZJgJn0W1_cMolqju8ONYg,5805
27
- tinybird/tb/modules/create.py,sha256=jz5jswVntvsnNN-IbCXoKw9pUKySx_IubpP0rxi7Iy0,17528
28
- tinybird/tb/modules/datasource.py,sha256=mZ9N9LxbNA9QoKSMbxcMiQkdaQkfFqLeFB9_88e3_68,17843
27
+ tinybird/tb/modules/create.py,sha256=sT0d7hbM1TX6nws6jY4TQIVGBtmt2xPUqUYmgHgHK30,18756
28
+ tinybird/tb/modules/datasource.py,sha256=0_6Cn07p5GoNBBGdu88pSeLvTWojln1-k23FsS8jTDs,17801
29
29
  tinybird/tb/modules/deployment.py,sha256=t6DDLJ1YdY3SJiTPbEG7CRblSLkbuqwzauQ9y65FWtY,27147
30
30
  tinybird/tb/modules/deprecations.py,sha256=rrszC1f_JJeJ8mUxGoCxckQTJFBCR8wREf4XXXN-PRc,4507
31
31
  tinybird/tb/modules/dev_server.py,sha256=57FCKuWpErwYUYgHspYDkLWEm9F4pbvVOtMrFXX1fVU,10129
@@ -63,7 +63,7 @@ tinybird/tb/modules/datafile/build_pipe.py,sha256=6Cwjf3BKEF3-oQ9PipsQfK-Z43nSwt
63
63
  tinybird/tb/modules/datafile/common.py,sha256=9mZqagXTjw6XXdNBvTWv_jQDaLIwNBmKAd6VxhxRuVo,91721
64
64
  tinybird/tb/modules/datafile/diff.py,sha256=MTmj53RYjER4neLgWVjabn-FKVFgh8h8uYiBo55lFQg,6757
65
65
  tinybird/tb/modules/datafile/exceptions.py,sha256=8rw2umdZjtby85QbuRKFO5ETz_eRHwUY5l7eHsy1wnI,556
66
- tinybird/tb/modules/datafile/fixture.py,sha256=DrRWivcvo_1rn7LlVUnHcXccdgx9yVj63mzBkUwCzk8,1420
66
+ tinybird/tb/modules/datafile/fixture.py,sha256=gftYWeweeQDFK3cHgUmSOfltNjZVOuMt8v7WTMLhGBw,1579
67
67
  tinybird/tb/modules/datafile/format_common.py,sha256=1V1ZQuphp8EH2hT-IfZQEgz_0b9QqY177nwX8aMUte4,1962
68
68
  tinybird/tb/modules/datafile/format_datasource.py,sha256=iWbeXruxC7OBmjNgurWt6ymcJlYzxfKwkGnhpcoSKEo,6190
69
69
  tinybird/tb/modules/datafile/format_pipe.py,sha256=DUGdmlzI146YDqTwW-7kSIOXocz4AH-md_LFGUm9hrc,7436
@@ -80,8 +80,8 @@ tinybird/tb_cli_modules/config.py,sha256=IsgdtFRnUrkY8-Zo32lmk6O7u3bHie1QCxLwgp4
80
80
  tinybird/tb_cli_modules/exceptions.py,sha256=pmucP4kTF4irIt7dXiG-FcnI-o3mvDusPmch1L8RCWk,3367
81
81
  tinybird/tb_cli_modules/regions.py,sha256=QjsL5H6Kg-qr0aYVLrvb1STeJ5Sx_sjvbOYO0LrEGMk,166
82
82
  tinybird/tb_cli_modules/telemetry.py,sha256=Hh2Io8ZPROSunbOLuMvuIFU4TqwWPmQTqal4WS09K1A,10449
83
- tinybird-0.0.1.dev182.dist-info/METADATA,sha256=CcRyE9gi46a71FVojswEwM9vjvsZsMN8hqOcS5DuSh8,1608
84
- tinybird-0.0.1.dev182.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
85
- tinybird-0.0.1.dev182.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
86
- tinybird-0.0.1.dev182.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
87
- tinybird-0.0.1.dev182.dist-info/RECORD,,
83
+ tinybird-0.0.1.dev184.dist-info/METADATA,sha256=rBeUzI1isxMpgMebrnRzC64xPiVvvz2OnQrIDq-Ppyw,1608
84
+ tinybird-0.0.1.dev184.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
85
+ tinybird-0.0.1.dev184.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
86
+ tinybird-0.0.1.dev184.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
87
+ tinybird-0.0.1.dev184.dist-info/RECORD,,