Uploaded image for project: 'Couchbase Documentation'
  1. Couchbase Documentation
  2. DOC-7030

Python - Add async programming examples

    XMLWordPrintable

Details

    Description

      Currently there are no asynchronous Python SDK examples within the documentation.

      This makes the API very difficult to use as it's not always as simple as just adding a few 'awaits' to the synchronous examples.

      We need a page for Python that's similar in scope and style to https://docs.couchbase.com/java-sdk/current/howtos/concurrent-async-apis.html so that users have a starting point for using the async API, even if it does not cover everything.

      In case it's at all useful, below is a simple example of using the async API to perform a N1QL query:

      import asyncio
      from acouchbase.cluster import Cluster
      from couchbase_core.cluster import PasswordAuthenticator
       
      async def main():
          conn_str = 'couchbase://10.143.201.101'
          cluster = Cluster(conn_str, authenticator=PasswordAuthenticator('Administrator', 'password'))
          await cluster.on_connect()  # This will wait until the cluster is connected
       
          res = cluster.query('select * from `test` limit 1;') 
          async for row in res:
              print(row)
       
      if __name__ == "__main__":
          asyncio.run(main())
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              richard.smedley Richard Smedley
              matt.carabine Matt Carabine (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty