<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Using Databricks asset bundles with typer instead of argparse in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/using-databricks-asset-bundles-with-typer-instead-of-argparse/m-p/99735#M40078</link>
    <description>&lt;P&gt;Typer can handle this syntax as well, I just tested it locally by passing the value for application-name in various formats:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Test 1&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;PS C:\my_repo&amp;gt; poetry run python -m typer .\entrypoint_typer.py run --application-name=182
2024-11-22 09:09:44,223 - root - INFO - application_name='182'&lt;/LI-CODE&gt;&lt;P&gt;Test 2&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;PS C:\my_repo&amp;gt; poetry run python -m typer .\entrypoint_typer.py run --application-name 182
2024-11-22 09:10:21,266 - root - INFO - application_name='182'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Still unsure why it doesn't work as part of the asset bundle though. It's not a critical issue since we can use argparse instead, but we still would love to know why one works while the other doesn't. Maybe it does come down to the implementation of typer, some aspect might be different when running it in Databricks.&lt;/P&gt;</description>
    <pubDate>Fri, 22 Nov 2024 08:13:22 GMT</pubDate>
    <dc:creator>VicS</dc:creator>
    <dc:date>2024-11-22T08:13:22Z</dc:date>
    <item>
      <title>Using Databricks asset bundles with typer instead of argparse</title>
      <link>https://community.databricks.com/t5/data-engineering/using-databricks-asset-bundles-with-typer-instead-of-argparse/m-p/98776#M39838</link>
      <description>&lt;P&gt;I want to use Databricks asset bundles - I'd like to use `typer` as a CLI tool, but I have only been able to set it up with `argparse`. Argparse seems to be able to retrieve the arguments from the databricks task, but not typer.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I specified two entrypoints in my pyproject.toml&lt;/P&gt;&lt;LI-CODE lang="python"&gt;[tool.poetry.scripts]
mypackage_ep_typer = "my_package.entrypoint_typer:main"
mypackage_ep_argparse = "my_package.entrypoint_argparse:entrypoint_generic"&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;I'm able to use the asset bundles with an entrypoint to my ELTL applications with argparse as follows in the &lt;STRONG&gt;entrypoint_argparse.py&lt;/STRONG&gt;:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;def entrypoint_generic():
	"""Execute the application."""
	logger.info("Executing 'argparse' entrypoint...")
	parser = argparse.ArgumentParser(description="My module.")
	parser.add_argument(
		"--applicationname",
		help="The name of the application to execute.",
		type=str,
		required=True,
		dest="applicationname",
	)
	args = parser.parse_args()
	logger.info(f"{args.applicationname=}")&lt;/LI-CODE&gt;&lt;P&gt;This one deploys and runs without any issues in the asset bundle's workflow task.&lt;/P&gt;&lt;P&gt;However, if I try the same with typer in &lt;STRONG&gt;entrypoint_typer.py&lt;/STRONG&gt;, I cannot get it to work:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def main(
	applicationname: Annotated[str, typer.Option(help="Application to execute.")]
	):
	"""Execute the application."""
	logger.info("Executing 'typer' entrypoint...")
	logger.info(f"{applicationname=}")&lt;/LI-CODE&gt;&lt;P&gt;I can run typer locally:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;&amp;gt; poetry run python -m typer .\entrypoint_typer.py run --applicationname MYAPPNAME
2024-11-06 xx:xx:xx - root - INFO - Executing 'typer' entrypoint...
2024-11-06 xx:xx:xx - root - INFO - applicationname='MYAPPNAME'&lt;/LI-CODE&gt;&lt;P&gt;But when I try to deploy and run my asset bundle, I get this error when the workflow task tries to start:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;TypeError: main() missing 1 required positional argument: 'applicationname'&lt;/LI-CODE&gt;&lt;P&gt;But I can see the parameter in the UI...&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DdqYAyd4" style="width: 999px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/12890i445D0CB9E663A897/image-size/large?v=v2&amp;amp;px=999" role="button" title="DdqYAyd4" alt="DdqYAyd4" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2024 10:32:44 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/using-databricks-asset-bundles-with-typer-instead-of-argparse/m-p/98776#M39838</guid>
      <dc:creator>VicS</dc:creator>
      <dc:date>2024-11-14T10:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using Databricks asset bundles with typer instead of argparse</title>
      <link>https://community.databricks.com/t5/data-engineering/using-databricks-asset-bundles-with-typer-instead-of-argparse/m-p/99722#M40073</link>
      <description>&lt;P&gt;When you used &lt;EM&gt;named_parameters&lt;/EM&gt;&amp;nbsp;in Databricks Workflows' python_wheel_task type, the arguments will be available to your program in form of -&lt;STRONG&gt;-key=value,&lt;/STRONG&gt; literally&lt;STRONG&gt;.&lt;/STRONG&gt;&amp;nbsp;Argparse can parse this, but can Typer? If not, you can switch from &lt;EM&gt;named_parameters&lt;/EM&gt; to&amp;nbsp;&lt;EM&gt;&lt;A href="https://docs.databricks.com/api/workspace/jobs/create#tasks-python_wheel_task-parameters" target="_self"&gt;parameters&lt;/A&gt;&lt;/EM&gt; where you have a bit more flexibility in how the parameters are presented, like space between key and value instead of equals sign.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Nov 2024 03:34:25 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/using-databricks-asset-bundles-with-typer-instead-of-argparse/m-p/99722#M40073</guid>
      <dc:creator>cgrant</dc:creator>
      <dc:date>2024-11-22T03:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using Databricks asset bundles with typer instead of argparse</title>
      <link>https://community.databricks.com/t5/data-engineering/using-databricks-asset-bundles-with-typer-instead-of-argparse/m-p/99735#M40078</link>
      <description>&lt;P&gt;Typer can handle this syntax as well, I just tested it locally by passing the value for application-name in various formats:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Test 1&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;PS C:\my_repo&amp;gt; poetry run python -m typer .\entrypoint_typer.py run --application-name=182
2024-11-22 09:09:44,223 - root - INFO - application_name='182'&lt;/LI-CODE&gt;&lt;P&gt;Test 2&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;PS C:\my_repo&amp;gt; poetry run python -m typer .\entrypoint_typer.py run --application-name 182
2024-11-22 09:10:21,266 - root - INFO - application_name='182'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Still unsure why it doesn't work as part of the asset bundle though. It's not a critical issue since we can use argparse instead, but we still would love to know why one works while the other doesn't. Maybe it does come down to the implementation of typer, some aspect might be different when running it in Databricks.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Nov 2024 08:13:22 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/using-databricks-asset-bundles-with-typer-instead-of-argparse/m-p/99735#M40078</guid>
      <dc:creator>VicS</dc:creator>
      <dc:date>2024-11-22T08:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using Databricks asset bundles with typer instead of argparse</title>
      <link>https://community.databricks.com/t5/data-engineering/using-databricks-asset-bundles-with-typer-instead-of-argparse/m-p/105116#M41997</link>
      <description>&lt;P&gt;If switching to &lt;CODE&gt;parameters&lt;/CODE&gt; does not resolve the issue, you might need to further debug by adding logging statements in your &lt;CODE&gt;typer&lt;/CODE&gt; entry point to see how the parameters are being received.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2025 07:11:37 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/using-databricks-asset-bundles-with-typer-instead-of-argparse/m-p/105116#M41997</guid>
      <dc:creator>NandiniN</dc:creator>
      <dc:date>2025-01-10T07:11:37Z</dc:date>
    </item>
  </channel>
</rss>

