Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to create blocks from Python API #9

Merged
merged 9 commits into from
Apr 11, 2024
Prev Previous commit
Next Next commit
Remove api key specification at CLI
  • Loading branch information
ml-evs committed Apr 11, 2024
commit 2a0f2bf11cb1da3be7ff6f82e9abd9be3f0fee9e
13 changes: 5 additions & 8 deletions src/datalab_api/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,13 @@ def launch(
def _get_client(
ctx: typer.Context,
instance_url: Optional[str] = None,
api_key: Optional[str] = None,
log_level: str = "WARNING",
):
client = getattr(ctx, "client", None)
if instance_url is None:
instance_url = getattr(ctx, "instance_url", None) # type: ignore
if client is None:
client = DatalabClient(datalab_api_url=instance_url, api_key=api_key, log_level=log_level) # type: ignore
client = DatalabClient(datalab_api_url=instance_url, log_level=log_level) # type: ignore
ctx.client = client
ctx.instance_url = client.datalab_api_url
return ctx.client
Expand All @@ -93,10 +92,9 @@ def _get_instance_url(ctx: typer.Context):
def authenticate(
ctx: typer.Context,
instance_url: Annotated[Optional[str], typer.Argument()] = None,
api_key: Optional[str] = None,
log_level: str = "WARNING",
):
client = _get_client(ctx, instance_url, api_key, log_level)
client = _get_client(ctx, instance_url, log_level)
user = client.authenticate()
console.print(
f"Welcome [red]{user['display_name']}[/red]!\nSuccessfully authenticated at [blue]{client.datalab_api_url}[/blue]."
Expand All @@ -109,11 +107,10 @@ def get(
item_type: str,
instance_url: Annotated[Optional[str], typer.Argument()] = None,
page_limit: int = 10,
api_key: Optional[str] = None,
log_level: str = "WARNING",
):
"""Get a table of items of the given type."""
client = _get_client(ctx, instance_url, api_key, log_level)
client = _get_client(ctx, instance_url, log_level)
items = client.get_items(item_type)
table = Table(title=f"/{item_type}/", show_lines=True)
table.add_column("type", overflow="crop", justify="center")
Expand All @@ -139,10 +136,10 @@ def get(

@app.command()
def info(
ctx: typer.Context, instance_url: str, api_key: Optional[str] = None, log_level: str = "WARNING"
ctx: typer.Context, instance_url: str, log_level: str = "WARNING"
):
"""Print the server info."""
client = _get_client(ctx, instance_url, api_key, log_level)
client = _get_client(ctx, instance_url, log_level)
pprint(client.get_info())


Expand Down
Loading