|
| 1 | +Introduction |
| 2 | +============ |
| 3 | + |
| 4 | +The Feldera Python SDK is meant to provide an easy and convenient way of |
| 5 | +interacting with Feldera. |
| 6 | + |
| 7 | + |
| 8 | +Please submit any feature request / bug reports to: |
| 9 | +https://github.com/feldera/feldera |
| 10 | + |
| 11 | + |
| 12 | +Installation |
| 13 | +************* |
| 14 | + |
| 15 | +.. code-block:: bash |
| 16 | +
|
| 17 | + pip install git+https://github.com/feldera/feldera#subdirectory=python |
| 18 | +
|
| 19 | +
|
| 20 | +Similarly, to install from a specific branch: |
| 21 | + |
| 22 | +.. code-block:: bash |
| 23 | +
|
| 24 | + $ pip install git+https://github.com/feldera/feldera@{BRANCH_NAME}#subdirectory=python |
| 25 | +
|
| 26 | +Replace ``{BRANCH_NAME}`` with the name of the branch you want to install from. |
| 27 | + |
| 28 | + |
| 29 | +Key Concepts |
| 30 | +************ |
| 31 | + |
| 32 | +* :class:`feldera.FelderaClient` or :class:`.Client` |
| 33 | + - This is the actual HTTP client used to make requests to your Feldera |
| 34 | + instance. |
| 35 | + - creating an instance of :class:`.Client` is usually the first thing you |
| 36 | + will do while working with Feldera. |
| 37 | + |
| 38 | + - Example: |
| 39 | + |
| 40 | + .. code-block:: python |
| 41 | +
|
| 42 | + from feldera import FelderaClient |
| 43 | +
|
| 44 | + client = FelderaClient("https://try.feldera.com", api_key="YOUR_API_KEY") |
| 45 | + |
| 46 | + - The API key may not be required if you are running Feldera locally. |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +* :class:`.SQLContext` |
| 51 | + - This represents the current context of your SQL program, data sources |
| 52 | + and sinks. In Feldera terminology, this represents both a Program and a |
| 53 | + Pipeline. |
| 54 | + |
| 55 | + - Example: |
| 56 | + |
| 57 | + .. code-block:: python |
| 58 | +
|
| 59 | + from feldera import SQLContext |
| 60 | +
|
| 61 | + sql = SQLContext("getting_started", client).get_or_create() |
| 62 | +
|
| 63 | + - The first parameter is the name of this SQL context. By default, this is |
| 64 | + the name used in both Feldera Program and Pipeline. |
| 65 | + - The second parameter here is :class:`.Client` that we created above. |
| 66 | + |
| 67 | +* :meth:`.SQLContext.run_to_completion` |
| 68 | + - Runs this Feldera pipeline to completion. Normally this means until the EoF |
| 69 | + has been reached for this input source. |
| 70 | + |
| 71 | + - Example: |
| 72 | + |
| 73 | + .. code-block:: python |
| 74 | + |
| 75 | + from feldera import SQLSchema |
| 76 | +
|
| 77 | + tbl_name = "user_data" |
| 78 | + view_name = "select_view" |
| 79 | +
|
| 80 | + # Declare input tables |
| 81 | + sql.register_table(tbl_name, SQLSchema({"name": "STRING"})) |
| 82 | +
|
| 83 | + # Register Views based on your queries |
| 84 | + query = f"SELECT * FROM {tbl_name}" |
| 85 | + sql.register_view(view_name, query) |
| 86 | +
|
| 87 | + # name for this connector |
| 88 | + in_con = "delta_input_conn" |
| 89 | +
|
| 90 | + # the configuration for this input source |
| 91 | + in_cfg = {...} |
| 92 | +
|
| 93 | + sql.connect_source_delta_table(tbl_name, in_con, in_cfg) |
| 94 | +
|
| 95 | + # name for this connector |
| 96 | + out_con = "delta_output_con" |
| 97 | +
|
| 98 | + # the configuration for this input source |
| 99 | + out_cfg = {...} |
| 100 | +
|
| 101 | + sql.connect_sink_delta_table(view_name, out_con, out_cfg) |
| 102 | +
|
| 103 | + sql.run_to_completion() |
| 104 | +
|
| 105 | + - Here, we register a data table which receives data from input sources. |
| 106 | + - Then, we register a view that performs operations on this input data. |
| 107 | + You can also register other views on top of existing views. |
| 108 | + - Then, we connect a source delta table to the previously defined table. |
| 109 | + - Then, we connect a sink delta table to the previously defined view. |
| 110 | + - Finally, we run the pipeline to completion. Feldera will fetch data from |
| 111 | + the source, perform the query you supplied and passes this data to the |
| 112 | + sink delta table. |
| 113 | + |
| 114 | + .. warning:: |
| 115 | + If the data source is streaming, this will block forever. |
| 116 | + In such cases, use :meth:`.SQLContext.start` instead. |
| 117 | + |
| 118 | +* :meth:`.SQLContext.start` |
| 119 | + - Starts the Feldera Pipeline and keeps it running indefinitely. |
| 120 | + - Example: |
| 121 | + |
| 122 | + .. code-block:: python |
| 123 | + |
| 124 | + sql.start() |
| 125 | +
|
| 126 | + - This tells Feldera to go ahead and start processing the data. |
| 127 | + |
| 128 | +Checkout the :doc:`/examples`. |
0 commit comments