Skip to content

Commit 389b1be

Browse files
authored
Reorganize Connectors (#529)
1 parent 85f9926 commit 389b1be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1508
-1360
lines changed

docs/api-reference/application.md

Lines changed: 30 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class Application()
1111
```
1212

13-
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/main/quixstreams/app.py#L63)
13+
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/chore/reorganize-connectors/quixstreams/app.py#L63)
1414

1515
The main Application class.
1616

@@ -66,7 +66,7 @@ def __init__(broker_address: Optional[Union[str, ConnectionConfig]] = None,
6666
commit_every: int = 0,
6767
consumer_extra_config: Optional[dict] = None,
6868
producer_extra_config: Optional[dict] = None,
69-
state_dir: str = "state",
69+
state_dir: Union[str, Path] = Path("state"),
7070
rocksdb_options: Optional[RocksDBOptionsType] = None,
7171
on_consumer_error: Optional[ConsumerErrorCallback] = None,
7272
on_processing_error: Optional[ProcessingErrorCallback] = None,
@@ -84,7 +84,7 @@ def __init__(broker_address: Optional[Union[str, ConnectionConfig]] = None,
8484
processing_guarantee: ProcessingGuarantee = "at-least-once")
8585
```
8686

87-
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/main/quixstreams/app.py#L101)
87+
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/chore/reorganize-connectors/quixstreams/app.py#L101)
8888

8989

9090
<br>
@@ -170,126 +170,15 @@ instead of the default one.
170170

171171
```python
172172
@classmethod
173-
def Quix(
174-
cls,
175-
consumer_group: Optional[str] = None,
176-
auto_offset_reset: AutoOffsetReset = "latest",
177-
consumer_extra_config: Optional[dict] = None,
178-
producer_extra_config: Optional[dict] = None,
179-
state_dir: str = "state",
180-
rocksdb_options: Optional[RocksDBOptionsType] = None,
181-
on_consumer_error: Optional[ConsumerErrorCallback] = None,
182-
on_processing_error: Optional[ProcessingErrorCallback] = None,
183-
on_producer_error: Optional[ProducerErrorCallback] = None,
184-
on_message_processed: Optional[MessageProcessedCallback] = None,
185-
consumer_poll_timeout: float = 1.0,
186-
producer_poll_timeout: float = 0.0,
187-
loglevel: Optional[Union[int, LogLevel]] = "INFO",
188-
quix_config_builder: Optional[QuixKafkaConfigsBuilder] = None,
189-
auto_create_topics: bool = True,
190-
use_changelog_topics: bool = True,
191-
topic_manager: Optional[QuixTopicManager] = None,
192-
request_timeout: float = 30,
193-
topic_create_timeout: float = 60,
194-
processing_guarantee: Literal["at-least-once",
195-
"exactly-once"] = "exactly-once"
196-
) -> Self
173+
def Quix(cls, *args, **kwargs)
197174
```
198175

199-
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/main/quixstreams/app.py#L353)
176+
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/chore/reorganize-connectors/quixstreams/app.py#L355)
200177

201-
>***NOTE:*** DEPRECATED: use Application with `quix_sdk_token` argument instead.
178+
RAISES EXCEPTION: DEPRECATED.
202179

203-
Initialize an Application to work with Quix Cloud,
204-
assuming environment is properly configured (by default in Quix Cloud).
205-
206-
It takes the credentials from the environment and configures consumer and
207-
producer to properly connect to the Quix Cloud.
208-
209-
>***NOTE:*** Quix Cloud requires `consumer_group` and topic names to be
210-
prefixed with workspace id.
211-
If the application is created via `Application.Quix()`, the real consumer
212-
group will be `<workspace_id>-<consumer_group>`,
213-
and the real topic names will be `<workspace_id>-<topic_name>`.
214-
215-
216-
217-
218-
<br>
219-
***Example Snippet:***
220-
221-
```python
222-
from quixstreams import Application
223-
224-
# Set up an `app = Application.Quix` and `sdf = StreamingDataFrame`;
225-
# add some operations to `sdf` and then run everything. Also shows off how to
226-
# use the quix-specific serializers and deserializers.
227-
228-
app = Application.Quix()
229-
input_topic = app.topic("topic-in", value_deserializer="quix")
230-
output_topic = app.topic("topic-out", value_serializer="quix_timeseries")
231-
df = app.dataframe(topic_in)
232-
df = df.to_topic(output_topic)
233-
234-
app.run()
235-
```
236-
237-
238-
<br>
239-
***Arguments:***
240-
241-
- `consumer_group`: Kafka consumer group.
242-
Passed as `group.id` to `confluent_kafka.Consumer`.
243-
Linked Environment Variable: `Quix__Consumer__Group`.
244-
Default - "quixstreams-default" (set during init).
245-
>***NOTE:*** Quix Applications will prefix it with the Quix workspace id.
246-
- `auto_offset_reset`: Consumer `auto.offset.reset` setting
247-
- `consumer_extra_config`: A dictionary with additional options that
248-
will be passed to `confluent_kafka.Consumer` as is.
249-
- `producer_extra_config`: A dictionary with additional options that
250-
will be passed to `confluent_kafka.Producer` as is.
251-
- `state_dir`: path to the application state directory.
252-
Default - `".state"`.
253-
- `rocksdb_options`: RocksDB options.
254-
If `None`, the default options will be used.
255-
- `consumer_poll_timeout`: timeout for `RowConsumer.poll()`. Default - `1.0`s
256-
- `producer_poll_timeout`: timeout for `RowProducer.poll()`. Default - `0`s.
257-
- `on_message_processed`: a callback triggered when message is successfully
258-
processed.
259-
- `loglevel`: a log level for "quixstreams" logger.
260-
Should be a string or `None`.
261-
If `None` is passed, no logging will be configured.
262-
You may pass `None` and configure "quixstreams" logger
263-
externally using `logging` library.
264-
Default - `"INFO"`.
265-
- `auto_create_topics`: Create all `Topic`s made via `Application.topic()`
266-
Default - `True`
267-
- `use_changelog_topics`: Use changelog topics to back stateful operations
268-
Default - `True`
269-
- `topic_manager`: A `QuixTopicManager` instance
270-
- `request_timeout`: timeout (seconds) for REST-based requests
271-
- `topic_create_timeout`: timeout (seconds) for topic create finalization
272-
- `processing_guarantee`: Use "exactly-once" or "at-least-once" processing.
273-
<br><br>***Error Handlers***<br>
274-
To handle errors, `Application` accepts callbacks triggered when
275-
exceptions occur on different stages of stream processing. If the callback
276-
returns `True`, the exception will be ignored. Otherwise, the exception
277-
will be propagated and the processing will eventually stop.
278-
- `on_consumer_error`: triggered when internal `RowConsumer` fails to poll
279-
Kafka or cannot deserialize a message.
280-
- `on_processing_error`: triggered when exception is raised within
281-
`StreamingDataFrame.process()`.
282-
- `on_producer_error`: triggered when RowProducer fails to serialize
283-
or to produce a message to Kafka.
284-
<br><br>***Quix Cloud Parameters***<br>
285-
- `quix_config_builder`: instance of `QuixKafkaConfigsBuilder` to be used
286-
instead of the default one.
287-
288-
289-
<br>
290-
***Returns:***
291-
292-
`Application` object
180+
use Application() with "quix_sdk_token" parameter or set the "Quix__Sdk__Token"
181+
environment variable.
293182

294183
<a id="quixstreams.app.Application.topic"></a>
295184

@@ -307,7 +196,7 @@ def topic(name: str,
307196
timestamp_extractor: Optional[TimestampExtractor] = None) -> Topic
308197
```
309198

310-
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/main/quixstreams/app.py#L494)
199+
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/chore/reorganize-connectors/quixstreams/app.py#L370)
311200

312201
Create a topic definition.
313202

@@ -389,14 +278,19 @@ def dataframe(topic: Optional[Topic] = None,
389278
source: Optional[BaseSource] = None) -> StreamingDataFrame
390279
```
391280

392-
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/main/quixstreams/app.py#L574)
281+
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/chore/reorganize-connectors/quixstreams/app.py#L450)
393282

394283
A simple helper method that generates a `StreamingDataFrame`, which is used
395284

396285
to define your message processing pipeline.
397286

398-
See :class:`quixstreams.dataframe.StreamingDataFrame` for more details.
287+
The topic is what the `StreamingDataFrame` will use as its input, unless
288+
a source is provided (`topic` is optional when using a `source`).
289+
290+
If both `topic` AND `source` are provided, the source will write to that topic
291+
instead of its default topic (which the `StreamingDataFrame` then consumes).
399292

293+
See :class:`quixstreams.dataframe.StreamingDataFrame` for more details.
400294

401295

402296
<br>
@@ -422,6 +316,7 @@ app.run()
422316

423317
- `topic`: a `quixstreams.models.Topic` instance
424318
to be used as an input topic.
319+
- `source`: a `quixstreams.sources` "BaseSource" instance
425320

426321

427322
<br>
@@ -439,7 +334,7 @@ to be used as an input topic.
439334
def stop(fail: bool = False)
440335
```
441336

442-
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/main/quixstreams/app.py#L620)
337+
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/chore/reorganize-connectors/quixstreams/app.py#L505)
443338

444339
Stop the internal poll loop and the message processing.
445340

@@ -466,7 +361,7 @@ to unhandled exception, and it shouldn't commit the current checkpoint.
466361
def get_producer() -> Producer
467362
```
468363

469-
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/main/quixstreams/app.py#L665)
364+
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/chore/reorganize-connectors/quixstreams/app.py#L550)
470365

471366
Create and return a pre-configured Producer instance.
472367
The Producer is initialized with params passed to Application.
@@ -501,7 +396,7 @@ with app.get_producer() as producer:
501396
def get_consumer(auto_commit_enable: bool = True) -> Consumer
502397
```
503398

504-
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/main/quixstreams/app.py#L695)
399+
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/chore/reorganize-connectors/quixstreams/app.py#L580)
505400

506401
Create and return a pre-configured Consumer instance.
507402

@@ -558,7 +453,7 @@ with app.get_consumer() as consumer:
558453
def clear_state()
559454
```
560455

561-
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/main/quixstreams/app.py#L745)
456+
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/chore/reorganize-connectors/quixstreams/app.py#L630)
562457

563458
Clear the state of the application.
564459

@@ -572,10 +467,12 @@ Clear the state of the application.
572467
def add_source(source: BaseSource, topic: Optional[Topic] = None) -> Topic
573468
```
574469

575-
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/main/quixstreams/app.py#L751)
470+
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/chore/reorganize-connectors/quixstreams/app.py#L636)
576471

577472
Add a source to the application.
578473

474+
Use when no transformations (which requires a `StreamingDataFrame`) are needed.
475+
579476
See :class:`quixstreams.sources.base.BaseSource` for more details.
580477

581478

@@ -593,10 +490,10 @@ Default: the source default
593490
#### Application.run
594491

595492
```python
596-
def run(dataframe: StreamingDataFrame)
493+
def run(dataframe: Optional[StreamingDataFrame] = None)
597494
```
598495

599-
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/main/quixstreams/app.py#L770)
496+
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/chore/reorganize-connectors/quixstreams/app.py#L657)
600497

601498
Start processing data from Kafka using provided `StreamingDataFrame`
602499

@@ -622,12 +519,6 @@ df.apply(lambda value, context: print('New message', value)
622519
app.run()
623520
```
624521

625-
626-
<br>
627-
***Arguments:***
628-
629-
- `dataframe`: instance of `StreamingDataFrame`
630-
631522
<a id="quixstreams.app.Application.setup_topics"></a>
632523

633524
<br><br>
@@ -638,7 +529,7 @@ app.run()
638529
def setup_topics()
639530
```
640531

641-
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/main/quixstreams/app.py#L890)
532+
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/chore/reorganize-connectors/quixstreams/app.py#L779)
642533

643534
Validate and create the topics
644535

@@ -650,7 +541,7 @@ Validate and create the topics
650541
class ApplicationConfig(BaseSettings)
651542
```
652543

653-
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/main/quixstreams/app.py#L1066)
544+
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/chore/reorganize-connectors/quixstreams/app.py#L955)
654545

655546
Immutable object holding the application configuration
656547

@@ -673,7 +564,7 @@ def settings_customise_sources(
673564
) -> Tuple[PydanticBaseSettingsSource, ...]
674565
```
675566

676-
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/main/quixstreams/app.py#L1101)
567+
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/chore/reorganize-connectors/quixstreams/app.py#L990)
677568

678569
Included to ignore reading/setting values from the environment
679570

@@ -687,7 +578,7 @@ Included to ignore reading/setting values from the environment
687578
def copy(**kwargs) -> Self
688579
```
689580

690-
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/main/quixstreams/app.py#L1114)
581+
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/chore/reorganize-connectors/quixstreams/app.py#L1003)
691582

692583
Update the application config and return a copy
693584

docs/api-reference/context.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
def set_message_context(context: Optional[MessageContext])
1313
```
1414

15-
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/main/quixstreams/context.py#L20)
15+
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/chore/reorganize-connectors/quixstreams/context.py#L20)
1616

1717
Set a MessageContext for the current message in the given `contextvars.Context`
1818

@@ -55,7 +55,7 @@ sdf = sdf.update(lambda value: alter_context(value))
5555
def message_context() -> MessageContext
5656
```
5757

58-
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/main/quixstreams/context.py#L51)
58+
[[VIEW SOURCE]](https://github.com/quixio/quix-streams/blob/chore/reorganize-connectors/quixstreams/context.py#L51)
5959

6060
Get a MessageContext for the current message, which houses most of the message
6161

0 commit comments

Comments
 (0)