Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Async support #6

Copy link
Copy link
@ramnes

Description

@ramnes
Issue body actions

Hey there, thanks for the neat library.

Do you have any plan to support native async features of Python for the client?

e.g. something in the lines of:

import asyncio
import random

from recombee_api_client.api_client import AsyncRecombeeClient, Region
from recombee_api_client.exceptions import APIException
from recombee_api_client.api_requests import *

async def main():
    client = AsyncRecombeeClient('--my-database-id--', '--db-private-token--', region=Region.US_WEST)
    
    #Generate some random purchases of items by users
    PROBABILITY_PURCHASED = 0.1
    NUM = 100
    purchase_requests = []
    
    for user_id in ["user-%s" % i for i in range(NUM) ]:
      for item_id in ["item-%s" % i for i in range(NUM) ]:
        if random.random() < PROBABILITY_PURCHASED:
    
          request = AddPurchase(user_id, item_id, cascade_create=True)
          purchase_requests.append(request)
    
    try:
        # Send the data to Recombee, use Batch for faster processing of larger data
        print('Send purchases')
        await client.send(Batch(purchase_requests))
    
        # Get recommendations for user 'user-25'
        response = await client.send(RecommendItemsToUser('user-25', 5))
        print("Recommended items: %s" % response)
    
        # User scrolled down - get next 3 recommended items
        response = await client.send(RecommendNextItems(response['recommId'], 3))
        print("Next recommended items: %s" % response)
    
    except APIException as e:
        print(e)


asyncio.run(main())
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.