Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async support #6

Open
ramnes opened this issue Sep 7, 2023 · 0 comments · May be fixed by #7
Open

Async support #6

ramnes opened this issue Sep 7, 2023 · 0 comments · May be fixed by #7

Comments

@ramnes
Copy link

ramnes commented Sep 7, 2023

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())
@ramnes ramnes linked a pull request Oct 2, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant