Suggestion: Add 'iter_all' as iterator version of 'get_all'
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 38/100
Hướng nghiên cứu
Bắt đầu với triển khai fetch_all hiện có trong hubspot/utils/objects.py và xem xét các entry point get_all và do_search được mô tả trong issue. Công việc được xem là hoàn tất khi client cung cấp một iterator tích hợp, xử lý các dạng khác nhau của đối số phân trang và hoạt động với các object API và association API được liệt kê.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
get_all reads all objects in memory before return. In most scenarios, an iterator can be a better fit.
My bypass solution:
This is based on fetch_all
PAGE_MAX_SIZE = 100
def iter_all(get_page_api_client, **kwargs):
after = kwargs.pop('after', None)
while True:
page = get_page_api_client.get_page(after=after, limit=PAGE_MAX_SIZE, **kwargs)
yield from page.results
if page.paging is None:
break
after = page.paging.next.after
It can be used like this
from itertools import islice
list(islice(iter_all(hs_client.crm.companies.basic_api, properties=['custom_field_1']), 2))
It can also be monkeypatched into suitable objects
import hubspot
def patch_iter_all():
def iter_all_for_crm(self, **kw):
yield from iter_all(self.basic_api, **kw)
hubspot.discovery.crm.tickets.discovery.Discovery.iter_all = iter_all_for_crm
hubspot.discovery.crm.products.discovery.Discovery.iter_all = iter_all_for_crm
hubspot.discovery.crm.quotes.discovery.Discovery.iter_all = iter_all_for_crm
hubspot.discovery.crm.contacts.discovery.Discovery.iter_all = iter_all_for_crm
hubspot.discovery.crm.deals.discovery.Discovery.iter_all = iter_all_for_crm
hubspot.discovery.crm.line_items.discovery.Discovery.iter_all = iter_all_for_crm
hubspot.discovery.crm.owners.discovery.Discovery.iter_all = iter_all_for_crm
hubspot.discovery.crm.companies.discovery.Discovery.iter_all = iter_all_for_crm
patch_iter_all()
Then the above example can simpler
list(islice(hs_client.crm.companies.iter_all(properties=['custom_field_1']), 2))
It would be nice if hubspot official api can have a 'iter_all' for every object that has 'get_all' function simply forward to fetch_all.
Just found there is another kind of 'get_all()' that returns forward paging object, like hs_client.crm.companies.associations_api.get_all() (where hs_client is the client object).
To iterate all items, it would be nice to have a common tool like this
def iter_from(f, **kwargs):
after = None
while True:
page = f(after=after, limit=100, **kwargs)
yield from page.results
if page.paging is None:
break
after = page.paging.next.after
Then it can be used as following
for item in iter_from(hs_client.crm.companies.associations_api.get_all, company_id='1234567', to_object_type='contact'):
# item is hubspot.crm.companies.models.associated_id.AssociatedId object
....
Edit: for functions like hs_client.crm.contacts.search_api.do_search the after and limit params are included in *Request object like PublicObjectSearchRequest.
Functions like hs_client.crm.companies.associations_api.get_all() have after and limit in function argument.
It would be nice if hubspot client can have a built-in pagination iterator.
- Ngôn ngữ chính
- Python
- Star
- 434
- Fork
- 126
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của HubSpot/hubspot-api-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
HubSpot/hubspot-api-python#497 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 58/100
HubSpot/hubspot-api-python#498 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
HubSpot/hubspot-api-python#496 ·
-
HubSpot v4 APIs are deprecated Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
HubSpot/hubspot-api-python#495 · 1 bình luận · 2 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
HubSpot/hubspot-api-python#494 ·
Tất cả issue của HubSpot/hubspot-api-python
Issue tương tự
-
[Bug] reef-hermes tells me to resume with hermes --resume, which does not work from my shell Đang mởarea: harness bug status: needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Human-Agent-Society/reef#625 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 80/100
learningequality/kolibri#15351 · 2 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Name consistency Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
eellak/triplestore#65 · 1 bình luận ·