Search code examples
pythonapache-kafkamemgraphdb

How can I create Kafka stream from Python?


How can I create a Kafka stream directly from Python? I know that I need to use GQLAlchemy but I don't know the exact commands.


Solution

  • GQLAlchemy is a fully open-source Python library and Object Graph Mapper (OGM) - a link between graph database objects and Python objects.

    An Object Graph Mapper or OGM provides a developer-friendly workflow that allows for writing object-oriented notation to communicate with graph databases. This means that instead of writing Cypher queries, you can write object-oriented code, which the OGM will automatically translate into Cypher queries.

    You can use the following code to connect to the Kafka stream:

    from gqlalchemy import MemgraphKafkaStream
    
    stream = MemgraphKafkaStream(name="ratings_stream", topics=["ratings"], transform="movielens.rating", bootstrap_servers="localhost:9093")
    db.create_stream(stream)
    db.start_stream(stream)