Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#124 0 commenti 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
38/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
python
Ambito
api

Direzione di ricerca

Inizia con l’implementazione esistente di fetch_all in hubspot/utils/objects.py e rivedi i punti di ingresso get_all e do_search descritti nell’issue. Il lavoro è completato quando il client fornisce un iteratore integrato che gestisce le diverse forme degli argomenti di paginazione e funziona con le API di oggetti e associazioni elencate.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
434
Fork
126
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di HubSpot/hubspot-api-python

Tutte le issue di HubSpot/hubspot-api-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.