This is an automated email from the ASF dual-hosted git repository.

pierrejeambrun pushed a commit to branch v3-0-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/v3-0-test by this push:
     new 95d67083b79 Sync python client readme (#51536) (#51573)
95d67083b79 is described below

commit 95d67083b795cd4dd5f48cd1e4b5f333d8231466
Author: Pierre Jeambrun <pierrejb...@gmail.com>
AuthorDate: Tue Jun 10 16:48:04 2025 +0200

    Sync python client readme (#51536) (#51573)
    
    * Sync python client readme
    
    Sync python client readme with
    https://github.com/apache/airflow-client-python/pull/135/files
    
    * Revert bad change from airflow-client-python
    
    * pre-commit pass
    
    (cherry picked from commit 1ccca8198229fbc04491fa35b6066b6872254208)
    
    Co-authored-by: r-richmond <rrichmond...@gmail.com>
---
 clients/python/README.md | 52 ++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 41 insertions(+), 11 deletions(-)

diff --git a/clients/python/README.md b/clients/python/README.md
index 2253aec8bcf..f071d077354 100644
--- a/clients/python/README.md
+++ b/clients/python/README.md
@@ -178,14 +178,6 @@ For details on enabling/configuring CORS, see
 To be able to meet the requirements of many organizations, Airflow supports 
many authentication methods,
 and it is even possible to add your own method.
 
-If you want to check which auth backend is currently set, you can use
-`airflow config get-value api auth_backends` command as in the example below.
-
-```bash
-$ airflow config get-value api auth_backends
-airflow.providers.fab.auth_manager.api.auth.backend.basic_auth
-```
-
 The default is to deny all requests.
 
 For details on configuring the authentication, see
@@ -279,24 +271,62 @@ import airflow_client.client
 
 ## Getting Started
 
+Before attempting the following examples ensure you have an account with API 
access.
+As an example you can create an account for usage with the API as follows 
using the Airflow CLI.
+
+```bash
+airflow users create -u admin-api -e admin-...@example.com -f admin-api -l 
admin-api -p $PASSWORD -r Admin
+```
+
 Please follow the [installation procedure](#installation--usage) and then run 
the following:
 
 ```python
 import airflow_client.client
+import requests
 from airflow_client.client.rest import ApiException
 from pprint import pprint
+from pydantic import BaseModel
+
+
+# What we expect back from auth/token
+class AirflowAccessTokenResponse(BaseModel):
+    access_token: str
+
+
+# An optional helper function to retrieve an access token
+def get_airflow_client_access_token(
+    host: str,
+    username: str,
+    password: str,
+) -> str:
+    url = f"{host}/auth/token"
+    payload = {
+        "username": username,
+        "password": password,
+    }
+    headers = {"Content-Type": "application/json"}
+    response = requests.post(url, json=payload, headers=headers)
+    if response.status_code != 201:
+        raise RuntimeError(f"Failed to get access token: 
{response.status_code} {response.text}")
+    response_success = AirflowAccessTokenResponse(**response.json())
+    return response_success.access_token
+
 
 # Defining the host is optional and defaults to http://localhost
 # See configuration.py for a list of all supported configuration parameters.
-configuration = airflow_client.client.Configuration(host="http://localhost";)
+host = "http://localhost";
+configuration = airflow_client.client.Configuration(host=host)
 
 # The client must configure the authentication and authorization parameters
 # in accordance with the API server security policy.
 # Examples for each auth method are provided below, use the example that
 # satisfies your auth use case.
 
-configuration.access_token = os.environ["ACCESS_TOKEN"]
-
+configuration.access_token = get_airflow_client_access_token(
+    host=host,
+    username="admin-api",
+    password=os.environ["PASSWORD"],
+)
 
 # Enter a context with an instance of the API client
 with airflow_client.client.ApiClient(configuration) as api_client:

Reply via email to