Skip to content

Commit dc44d9c

Browse files
committed
Support RecommendNextItems endpoint
1 parent 021d747 commit dc44d9c

File tree

93 files changed

+1952
-1803
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1952
-1803
lines changed

README.rst

+8-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Basic example
3232
3333
from recombee_api_client.api_client import RecombeeClient
3434
from recombee_api_client.exceptions import APIException
35-
from recombee_api_client.api_requests import AddPurchase, RecommendItemsToUser, Batch
35+
from recombee_api_client.api_requests import *
3636
import random
3737
3838
client = RecombeeClient('--my-database-id--', '--db-private-token--')
@@ -55,8 +55,12 @@ Basic example
5555
client.send(Batch(purchase_requests))
5656
5757
# Get recommendations for user 'user-25'
58-
recommended = client.send(RecommendItemsToUser('user-25', 5))
59-
print("Recommended items: %s" % recommended)
58+
response = client.send(RecommendItemsToUser('user-25', 5))
59+
print("Recommended items: %s" % response)
60+
61+
# User scrolled down - get next 3 recommended items
62+
response = client.send(RecommendNextItems(response['recommId'], 3))
63+
print("Next recommended items: %s" % response)
6064
6165
except APIException as e:
6266
print(e)
@@ -146,7 +150,7 @@ Using property values
146150
)
147151
148152
# Perform personalized full-text search with a user's search query (e.g. 'computers').
149-
matches = client.send(SearchItems('user-42', 'computers', 5))
153+
matches = client.send(SearchItems('user-42', 'computers', 5, scenario='search_top'))
150154
print("Matched items: %s" % matches)
151155
152156
------------------
@@ -160,7 +164,6 @@ We are doing our best to provide the fastest and most reliable service, but prod
160164
Example:
161165

162166
.. code-block:: python
163-
164167
from recombee_api_client.exceptions import *
165168
166169
try:

recombee_api_client/api_client.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616
class RecombeeClient:
1717
"""
1818
Client for sending requests to Recombee recommender system
19+
20+
:param database_id: Name of your database_id at Recombee
21+
22+
:param token: Secret token obtained from Recombee for signing requests
23+
24+
:param protocol: Default protocol for sending requests. Possible values: 'http', 'https'.
1925
"""
2026
BATCH_MAX_SIZE = 10000
2127

2228
def __init__(self, database_id, token, protocol = 'https', options = {}):
23-
"""
24-
@param database_id: Name of your database_id at Recombee
25-
@param token: Secret token obtained from Recombee for signing requests
26-
@param protocol: Default protocol for sending requests. Possible values: 'http', 'https'.
27-
"""
2829
self.database_id = database_id
2930
self.token = token
3031
self.protocol = protocol
@@ -38,7 +39,7 @@ def __init__(self, database_id, token, protocol = 'https', options = {}):
3839

3940
def send(self, request):
4041
"""
41-
@param request: Request to be sent to Recombee recommender
42+
:param request: Request to be sent to Recombee recommender
4243
"""
4344

4445
if isinstance(request, Batch) and len(request.requests) > self.BATCH_MAX_SIZE:
@@ -63,7 +64,7 @@ def send(self, request):
6364

6465
@staticmethod
6566
def __get_http_headers(additional_headers=None):
66-
headers = {'User-Agent': 'recombee-python-api-client/3.0.0'}
67+
headers = {'User-Agent': 'recombee-python-api-client/3.1.0'}
6768
if additional_headers:
6869
headers.update(additional_headers)
6970
return headers

recombee_api_client/api_requests/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@
5454
from recombee_api_client.api_requests.list_item_view_portions import ListItemViewPortions
5555
from recombee_api_client.api_requests.list_user_view_portions import ListUserViewPortions
5656
from recombee_api_client.api_requests.recommend_items_to_user import RecommendItemsToUser
57-
from recombee_api_client.api_requests.recommend_users_to_user import RecommendUsersToUser
5857
from recombee_api_client.api_requests.recommend_items_to_item import RecommendItemsToItem
58+
from recombee_api_client.api_requests.recommend_next_items import RecommendNextItems
59+
from recombee_api_client.api_requests.recommend_users_to_user import RecommendUsersToUser
5960
from recombee_api_client.api_requests.recommend_users_to_item import RecommendUsersToItem
6061
from recombee_api_client.api_requests.search_items import SearchItems
6162
from recombee_api_client.api_requests.user_based_recommendation import UserBasedRecommendation

recombee_api_client/api_requests/add_bookmark.py

+18-17
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,28 @@
66
class AddBookmark(Request):
77
"""
88
Adds a bookmark of a given item made by a given user.
9+
10+
Required parameters:
11+
12+
:param user_id: User who bookmarked the item
13+
14+
:param item_id: Bookmarked item
15+
16+
17+
Optional parameters:
18+
19+
:param timestamp: UTC timestamp of the bookmark as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
20+
21+
:param cascade_create: Sets whether the given user/item should be created if not present in the database.
22+
23+
:param recomm_id: If this bookmark is based on a recommendation request, `recommId` is the id of the clicked recommendation.
24+
25+
:param additional_data: A dictionary of additional data for the interaction.
26+
927
1028
"""
1129

1230
def __init__(self, user_id, item_id, timestamp=DEFAULT, cascade_create=DEFAULT, recomm_id=DEFAULT, additional_data=DEFAULT):
13-
"""
14-
Required parameters:
15-
@param user_id: User who bookmarked the item
16-
17-
@param item_id: Bookmarked item
18-
19-
20-
Optional parameters:
21-
@param timestamp: UTC timestamp of the bookmark as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
22-
23-
@param cascade_create: Sets whether the given user/item should be created if not present in the database.
24-
25-
@param recomm_id: If this bookmark is based on a recommendation request, `recommId` is the id of the clicked recommendation.
26-
27-
@param additional_data: A dictionary of additional data for the interaction.
28-
29-
"""
3031
self.user_id = user_id
3132
self.item_id = item_id
3233
self.timestamp = timestamp

recombee_api_client/api_requests/add_cart_addition.py

+22-21
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,32 @@
66
class AddCartAddition(Request):
77
"""
88
Adds a cart addition of a given item made by a given user.
9+
10+
Required parameters:
11+
12+
:param user_id: User who added the item to the cart
13+
14+
:param item_id: Item added to the cart
15+
16+
17+
Optional parameters:
18+
19+
:param timestamp: UTC timestamp of the cart addition as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
20+
21+
:param cascade_create: Sets whether the given user/item should be created if not present in the database.
22+
23+
:param amount: Amount (number) added to cart. The default is 1. For example if `user-x` adds two `item-y` during a single order (session...), the `amount` should equal to 2.
24+
25+
:param price: Price of the added item. If `amount` is greater than 1, sum of prices of all the items should be given.
26+
27+
:param recomm_id: If this cart addition is based on a recommendation request, `recommId` is the id of the clicked recommendation.
28+
29+
:param additional_data: A dictionary of additional data for the interaction.
30+
931
1032
"""
1133

1234
def __init__(self, user_id, item_id, timestamp=DEFAULT, cascade_create=DEFAULT, amount=DEFAULT, price=DEFAULT, recomm_id=DEFAULT, additional_data=DEFAULT):
13-
"""
14-
Required parameters:
15-
@param user_id: User who added the item to the cart
16-
17-
@param item_id: Item added to the cart
18-
19-
20-
Optional parameters:
21-
@param timestamp: UTC timestamp of the cart addition as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
22-
23-
@param cascade_create: Sets whether the given user/item should be created if not present in the database.
24-
25-
@param amount: Amount (number) added to cart. The default is 1. For example if `user-x` adds two `item-y` during a single order (session...), the `amount` should equal to 2.
26-
27-
@param price: Price of the added item. If `amount` is greater than 1, sum of prices of all the items should be given.
28-
29-
@param recomm_id: If this cart addition is based on a recommendation request, `recommId` is the id of the clicked recommendation.
30-
31-
@param additional_data: A dictionary of additional data for the interaction.
32-
33-
"""
3435
self.user_id = user_id
3536
self.item_id = item_id
3637
self.timestamp = timestamp

recombee_api_client/api_requests/add_detail_view.py

+20-19
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,30 @@
66
class AddDetailView(Request):
77
"""
88
Adds a detail view of a given item made by a given user.
9+
10+
Required parameters:
11+
12+
:param user_id: User who viewed the item
13+
14+
:param item_id: Viewed item
15+
16+
17+
Optional parameters:
18+
19+
:param timestamp: UTC timestamp of the view as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
20+
21+
:param duration: Duration of the view
22+
23+
:param cascade_create: Sets whether the given user/item should be created if not present in the database.
24+
25+
:param recomm_id: If this detail view is based on a recommendation request, `recommId` is the id of the clicked recommendation.
26+
27+
:param additional_data: A dictionary of additional data for the interaction.
28+
929
1030
"""
1131

1232
def __init__(self, user_id, item_id, timestamp=DEFAULT, duration=DEFAULT, cascade_create=DEFAULT, recomm_id=DEFAULT, additional_data=DEFAULT):
13-
"""
14-
Required parameters:
15-
@param user_id: User who viewed the item
16-
17-
@param item_id: Viewed item
18-
19-
20-
Optional parameters:
21-
@param timestamp: UTC timestamp of the view as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
22-
23-
@param duration: Duration of the view
24-
25-
@param cascade_create: Sets whether the given user/item should be created if not present in the database.
26-
27-
@param recomm_id: If this detail view is based on a recommendation request, `recommId` is the id of the clicked recommendation.
28-
29-
@param additional_data: A dictionary of additional data for the interaction.
30-
31-
"""
3233
self.user_id = user_id
3334
self.item_id = item_id
3435
self.timestamp = timestamp

recombee_api_client/api_requests/add_group.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
class AddGroup(Request):
77
"""
88
Creates new group in the database.
9+
Required parameters:
10+
11+
:param group_id: ID of the group to be created.
12+
13+
914
"""
1015

1116
def __init__(self, group_id):
12-
"""
13-
Required parameters:
14-
@param group_id: ID of the group to be created.
15-
16-
"""
1717
self.group_id = group_id
1818
self.timeout = 1000
1919
self.ensure_https = False

recombee_api_client/api_requests/add_item.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ class AddItem(Request):
88
Adds new item of given `itemId` to the items catalog.
99
1010
All the item properties for the newly created items are set null.
11+
12+
Required parameters:
13+
14+
:param item_id: ID of the item to be created.
15+
1116
1217
"""
1318

1419
def __init__(self, item_id):
15-
"""
16-
Required parameters:
17-
@param item_id: ID of the item to be created.
18-
19-
"""
2020
self.item_id = item_id
2121
self.timeout = 1000
2222
self.ensure_https = False

recombee_api_client/api_requests/add_item_property.py

+33-33
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,43 @@
66
class AddItemProperty(Request):
77
"""
88
Adding an item property is somehow equivalent to adding a column to the table of items. The items may be characterized by various properties of different types.
9+
10+
Required parameters:
11+
12+
:param property_name: Name of the item property to be created. Currently, the following names are reserved:`id`, `itemid`, case insensitively. Also, the length of the property name must not exceed 63 characters.
13+
14+
15+
:param type: Value type of the item property to be created. One of: `int`, `double`, `string`, `boolean`, `timestamp`, `set`, `image` or `imageList`.
16+
17+
18+
* `int`- Signed integer number.
19+
20+
21+
* `double` - Floating point number. It uses 64-bit base-2 format (IEEE 754 standard).
22+
23+
24+
* `string` - UTF-8 string.
25+
26+
27+
* `boolean` - *true* / *false*
28+
29+
30+
* `timestamp` - Value representing date and time.
31+
32+
33+
* `set` - Set of strings.
34+
35+
36+
* `image` - URL of an image (`jpeg`, `png` or `gif`).
37+
38+
39+
* `imageList` - List of URLs that refer to images.
40+
41+
942
1043
"""
1144

1245
def __init__(self, property_name, type):
13-
"""
14-
Required parameters:
15-
@param property_name: Name of the item property to be created. Currently, the following names are reserved:`id`, `itemid`, case insensitively. Also, the length of the property name must not exceed 63 characters.
16-
17-
18-
@param type: Value type of the item property to be created. One of: `int`, `double`, `string`, `boolean`, `timestamp`, `set`, `image` or `imageList`.
19-
20-
21-
* `int`- Signed integer number.
22-
23-
24-
* `double` - Floating point number. It uses 64-bit base-2 format (IEEE 754 standard).
25-
26-
27-
* `string` - UTF-8 string.
28-
29-
30-
* `boolean` - *true* / *false*
31-
32-
33-
* `timestamp` - Value representing date and time.
34-
35-
36-
* `set` - Set of strings.
37-
38-
39-
* `image` - URL of an image (`jpeg`, `png` or `gif`).
40-
41-
42-
* `imageList` - List of URLs that refer to images.
43-
44-
45-
"""
4646
self.property_name = property_name
4747
self.type = type
4848
self.timeout = 100000

0 commit comments

Comments
 (0)