Skip to main content

Work with BigQuery data as you do with lists in python

Project description

Introduction

This project serves as a BigQuery helper that allows you to query data from BigQuery, without worrying about memory limitation concerns, it makes working with BigQuery data as easy as working with lists in python

Installation :

python3.8 -m pip install bq-iterate

Usage

from bq_iterate import BqQueryRowIterator, batchify_iterator
query = "select * from <project_id>.<dataset_id>.<table_id>"
row_itrator = BqQueryRowIterator(query=query, batch_size=2000000) #  choose a batch_size that will fit into your memory
batches = batchify_iterator(row_itrator, batch_slice=50000) #  choose a batch_slice that will fit into your memory
data = []
for batch in batches:
    # do your batch processing here
    data.append(len(batch))
print(sum(data))

What happens behind the scenes :

bq_iterate provide two functionalities :

  • 2 classes BqQueryIterator and BqTableRowIterator, they behave like an iterator, where they hold only <batch_size> elements in memory and when you want to access the element <batch_size + 1> the iterator calls in memory the next batch_size + 1 elements

  • A function batchify_iterator, what this function does, it takes an iterator and yields slices of it, the <batch_slice> can be bigger than the <batch_size> even if by common sens it's supposed to be smaller, it doesn't matter, since batchify_iterator will create in memory at each batch it yields, a list of <batch_slice> elements, once the batch consumed it freed from memory, since it's a generator

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bq_iterate-0.1.7.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bq_iterate-0.1.7-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file bq_iterate-0.1.7.tar.gz.

File metadata

  • Download URL: bq_iterate-0.1.7.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Darwin/20.6.0

File hashes

Hashes for bq_iterate-0.1.7.tar.gz
Algorithm Hash digest
SHA256 5517e4568e715cacecf319d8d4c7dc6715affbd3fb0807ac01c64acdd25e8db8
MD5 bfd7adba68be24a3338c6a62f676481f
BLAKE2b-256 9f160a1b09968e2d3edf935cf002c25b7577129f820d11aebf7ade2cb1a19a19

See more details on using hashes here.

File details

Details for the file bq_iterate-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: bq_iterate-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Darwin/20.6.0

File hashes

Hashes for bq_iterate-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 3e4c1f9e9bb88ffc9670799b7694e550a069904be0dc897fbc5789d6bb2adbc9
MD5 1091b8fd6bd90662eb1c1d18b7a6ec4c
BLAKE2b-256 cdf3fcb40ccf02805ed0eeceb4014def5d29ff9841991cd2e00e9f81bafc95b7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page