kaxil commented on code in PR #63017: URL: https://github.com/apache/airflow/pull/63017#discussion_r2898439645
########## airflow-ctl/docs/howto/index.rst: ########## @@ -114,6 +114,35 @@ This parameter is useful when you want to manage multiple Airflow environments. Useful when there's no keyring available in the system where airflowctl is running. Set ``AIRFLOW_CLI_TOKEN`` or use the ``--api-token`` flag for next commands. + +Use Airflow Ctl (airflowctl) as SDK +''''''''''''''''''''''''''''''''''' +airflowctl can also be used as a Python SDK to interact with the Airflow API programmatically. +You can import the necessary modules and use the functions provided by airflowctl to perform various operations on the Airflow API. + + +.. code-block:: python + + import httpx + from airflow_ctl.api.client import Client, Credentials, ServerResponseError + from airflowctl.api.datamodels.generated import DAGPatchBody + + # Reusable API Client until token expires + api_client = Client( + base_url="AIRFLOW_API_URL", + limits=httpx.Limits(max_keepalive_connections=1, max_connections=1), + token="TOKEN", + ) + + # Example: Pausing a DAG + dag_id = "EXAMPLE_DAG_ID" + try: + api_client.dags.update(dag_id=dag_id, dag_body=DAGPatchBody(is_paused="pause")) + except ServerResponseError as e: + # Handle error + pass Review Comment: haha yeah I had say keep `airflowctl` only for CLI -- the only public interface is CLI interaction -- so we can change anything internal as long as CLI works the same - same args/params etc. We already have https://github.com/apache/airflow-client-python -- although it is tied to a version. Keep version compat for a library is very difficult over CLI. So I'd suggest don't recommend this to the users :) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
