Skip to main content

Vaknl-gcp

Package for working with dataclasses and Google cloud instances as Bigquery and Storage. For this to work the dataclasses need to contain only basic python variables as: str, int, dict, list etc.

Prerequisites

These modules dependant on the environment variable GOOGLE_CLOUD_PROJECT a.k.a. gcp project id.

Bigquery

query(query):

Execute query and log errors

returns query_job

stream_to_bigquery(objects: list, table_ref):

Cast python objects to json and stream them to GBQ Note: this is more expensive compared to using buckets but also quicker

returns table ref

write_disposition_bucket(table_ref, blob_name, write_disposition):

Get data from bucket to GBQ using a write_disposition method

Requires: bucket with name storage_to_bigquery-[project-id]

  • WRITE_DISPOSITION_UNSPECIFIED Unknown.
  • WRITE_EMPTY This job should only be writing to empty tables.
  • WRITE_TRUNCATE This job will truncate table data and write from the beginning.
  • WRITE_APPEND This job will append to a table.
returns load_job.result 

Storage

Requires: bucket with name storage_to_bigquery-[project-id]

def storage_to_bigquery(objects: list, table_ref, write_disposition):

Function that stores data into multiple storage blobs. Afterwards these wil be composed into one storage blob The reason for this process is to downsize the sie of the data send to Google Cloud Storage.

Args:
    objects: dataclasses to process
    table_ref: dataset_name.table_name
    write_disposition: how to write to google bigquery
    batch_size: row size blobs will be created in google storage before they are composed and send to bigquery
    objects_name: name of the them objects stored in storage 

batch_storage_to_bigquery(self, objects: list, table_ref, write_disposition, finished: bool = True, batch_size=5000, objects_name=None):

Function that stores data into multiple storage blobs. If finished these wil be composed into one storage blob. The reason for this process is to downsize the sie of the data send to Google Cloud Storage.

Args:
    objects: dataclasses to process
    table_ref: dataset_name.table_name
    write_disposition: how to write to google bigquery
    finished: triggers composing all the blobs and storing them in one procedure
    batch_size: row size blobs will be created in google storage before they are composed and send to bigquery
    objects_name: name of the them objects stored in storage

single_storage_to_bigquery(object, table_ref, write_disposition, batch_size=500, object_name=None):

Function that stores data into a storage blob. Then check if there are more than the batch_size. If so it will compose similar blobs and send them to google bigquery. The reason for this process is to not stream single rows of data into bigquery but wait until there are more and than send them together.

Args:            
    object: dataclass
    table_ref: dataset_name.table_name
    write_disposition: how to write to google bigquery
    batch_size: how many blobs until composing and sending to google bigquery
    object_name: name of the them object stored in storage 

list_blobs_with_prefix(bucket_name, prefix, delimiter=None):):

Lists all the blobs in the bucket that begin with the prefix.

This can be used to list all blobs in a "folder", e.g. "public/".

The delimiter argument can be used to restrict the results to only the
"files" in the given "folder". Without the delimiter, the entire tree under
the prefix is returned. For example, given these blobs:

    a/1.txt
    a/b/2.txt

If you just specify prefix = 'a', you'll get back:

    a/1.txt
    a/b/2.txt

However, if you specify prefix='a' and delimiter='/', you'll get back:

    a/1.txt

Additionally, the same request will return blobs.prefixes populated with:

    a/b/

Args:
    bucket_name: bucket_name
    prefix: string
    delimiter: string

Return:
    list: blobs

Tasks

create_basic_task(url, queue, payload, task_name=None, in_seconds=None):

Creates a task that will be placed in a queue

Arg:
    url: url link like http://example.nl/
    queue: name of queue
    payload: dict
    task_name: str
    in_seconds: int

Returns:
    A :class:`~google.cloud.tasks_v2.types.Task` instance.

Scheduler

get_schedulers():

Gets back all schedulers form a gcp project

returns list[Schedule]

create_schedule(schedule:Schedule):

Creates a new Schedule

Arg: 
    schedule: class: `vaknl-gcp.Scheduler.Schedule`
 
Returns:
    A :class:`~google.cloud.scheduler_v1.types.Job` instance.

delete_schedule(name:str):

Deletes a schedule

Arg:
    name: str name of the schedule

Returns:
    A :class:`~google.cloud.scheduler_v1.types.Job` instance.

Secrets (beta)

get_default_secret(secret_id):

returns json

Metadata

Release files for vaknl-gcp 1.3.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vaknl-gcp 1.3.7
File Size Uploaded Provenance Actions
vaknl-gcp-1.3.7.tar.gz 10.7 kB Without provenance Details for vaknl-gcp-1.3.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for vaknl-gcp 1.3.7
File Interpreter ABI Platform Actions
vaknl_gcp-1.3.7-py3-none-any.whl Python 3 none any Details for vaknl_gcp-1.3.7-py3-none-any.whl

Total release size: 23.7 kB

Release files / vaknl-gcp-1.3.7.tar.gz

Download URL vaknl-gcp-1.3.7.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d17d9c19b3e43f644b62d68e6dbfee16cd420bcc71c06853f206c45716395fd7
BLAKE2b-256 checksum
How to use checksums
972e78ff6a1a66069b0a3e21ea0727e3dd33c0b875f923c194cdd7c2ca2e1aef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.2

Release files / vaknl_gcp-1.3.7-py3-none-any.whl

Download URL vaknl_gcp-1.3.7-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
68901e088a4bd6c5fe0b5a77f7b0a6f4ff6ed219a1ef7c064faa38e1fcf5c9e2
BLAKE2b-256 checksum
How to use checksums
9ab779628c550c7613ae4b9fde9329fc17862a97e2947d0de980e87b324183e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.2

Security for vaknl-gcp 1.3.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page