Skip to content

[Feature]: Automatically register stream classes as they are declared #953

@edgarrmondragon

Description

@edgarrmondragon

Feature scope

Taps (catalog, state, stream maps, etc.)

Description

The current pattern we enforce through our documentation and cookiecutter for adding new streams to an HTTP tap is implement a custom MyTap.discover_streams that returns a list of the desired stream instances.

This pattern may provide some consistency but it could be mildly annoying for a developer to remember they have to:

  1. import the new stream class,

  2. add the class to a module-level collection,

  3. implement (once) the discover_streams method:

    from tap_example.streams import NewStream
    
    STREAM_CLASSES = [NewStream]
    
    class TapExample(Tap):
      def discover_streams(self):
        return [stream_class(self) for stream_class in STREAM_CLASSES]

A better approach might get inspiration from other OOP frameworks, like Django. There, database models/tables are defined as classes and whenever some abstraction is required for a set of models, it's also a model class, but explicitly declared as abstract, so it doesn't map to a table in the database.

So, a similar thing in the SDK might look like this:

class MyAPIStream(RESTStream, abstract=True):
  ...

class UsersStream(MyAPIStream):
  name = "users"

Under the hood

  • MyAPIStream would not be registered, as it's declared to be abstract,
  • UsersStream would be registered,
  • The default implementation of discover_streams would read UsersStream from the underlying class registry and instantiate them appropriately.

Metadata

Metadata

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions