Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Suggestion: Add 'iter_all' as iterator version of 'get_all'

未关闭
#124 0 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
38/100
Issue 类型
功能
描述清晰度
需要澄清
活跃度
停滞
技术栈
python
领域
api

调研方向

从 hubspot/utils/objects.py 中现有的 fetch_all 实现开始,并检查 issue 中描述的 get_all 和 do_search 入口点。当客户端提供一个内置迭代器,能够处理不同形式的分页参数,并且适用于列出的对象 API 和关联 API 时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Python
星标
434
派生
126
PR 合并指标
30 天内没有已合并 PR

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

HubSpot/hubspot-api-python 的其他 Issue

查看 HubSpot/hubspot-api-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。