Skip to main content

Provides some helper functions previously used by The Sensible Code Company's Data Services team.

Project description

data-services-helpers

A module containing classes and functions previously used by The Sensible Code Company's Data Services team.

(The Sensible Code Company is now Cantabular Ltd.)

Warning: This is now in maintenance mode.

It has been updated to work with Python 3.14 but there are no guarantees on future maintenance.

Installation

For the current release:

pip install dshelpers

Usage

batch_processor

with batch_processor(callback_function(), batch_size=2000) as b:
    # loop to make rows here
    b.push(row)

Here, push on the batch_processor queues items in a list. When the context manager is exited, calls the callback_function with the list of items.

Often used to bundle multiple calls to scraperwiki.sqlite.save when saving data to a database.

install_cache

install_cache(expire_after=12 * 3600, cache_post=False)

For installing a requests_cache; requires the requests-cache package.

expire_after is the cache expiry time in seconds.

cache_post defines if HTTP POST requests should be cached as well.

download_url

download_url(url, back_off=True, **kwargs)

Retrieve the content of url, by default using requests.request('GET', url), and return a file-like object. If back_off=True, then this will retry (with backoff) on failure; otherwise, only one attempt is made. Returns the response.content as a StringIO object.

The **kwargs can be arguments that requests recognises, e.g. method or headers.

request_url

request_url(url, back_off=True, **kwargs)

As download_url, but returns the response object.

Tests

Run with make test.

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

dshelpers-2.0.2.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

dshelpers-2.0.2-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file dshelpers-2.0.2.tar.gz.

File metadata

  • Download URL: dshelpers-2.0.2.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for dshelpers-2.0.2.tar.gz
Algorithm Hash digest
SHA256 652f17f9f210ad07a3b3eed968d4abc6da245f0f0da1307cebe6552bc76f224f
MD5 cd722ab5735395a5aa13ce1544fe8144
BLAKE2b-256 bd9b2ac4db937feccf75984942acd38747ab0493512491bcc4e227f21d0eee92

See more details on using hashes here.

Provenance

The following attestation bundles were made for dshelpers-2.0.2.tar.gz:

Publisher: ci-build.yml on cantabular/data-services-helpers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dshelpers-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: dshelpers-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for dshelpers-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d8f870995b718c9c2bea23fb45d5df4caba74bfa4070a1f27633de7e25dcc497
MD5 cb3b91ea3952dfb74a6a184bb2fc8f88
BLAKE2b-256 19a68a2ec72a28415d7133cf46f71b1e21124a50126422888806a6f341b9862d

See more details on using hashes here.

Provenance

The following attestation bundles were made for dshelpers-2.0.2-py3-none-any.whl:

Publisher: ci-build.yml on cantabular/data-services-helpers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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