Skip to main content

Upload a local CSV file to a BigQuery table via the bq CLI

Project description

bqcsv

Upload a local CSV file to BigQuery using the bq CLI and your existing gcloud authentication.

Why a dedicated CLI tool?

Out of the box, Google's bq CLI cannot create a table with column names inferred from a CSV file.

bqcsv fixes that:

  • detects the schema from the CSV file
  • creates a table with proper column names and types
  • loads the CSV file using bq load

Authentication

No additional authentication is needed.

bqcsv uses your existing authentication via gcloud auth login.

Requirements

How to use bqcsv

Upload a CSV file to a table

To upload a CSV file, specify your project ID, dataset ID, and table name:

bqcsv data.csv --project my-gcp-project --dataset staging --table events_raw

The --table argument is optional. By default, bqcsv derives the table name from the CSV file:

bqcsv data.csv --project my-gcp-project --dataset staging

# is identical to

bqcsv data.csv --project my-gcp-project --dataset staging --table data

Saving your configuration

To avoid passing --project, --dataset, or --table on every run, save them to your local config:

bqcsv config set --project my-gcp-project --dataset analytics --table events
bqcsv config show

Defaults are stored in ~/.config/bqcsv/config.toml.

After you set your defaults, you can call bqcsv without arguments:

bqcsv data.csv

If you have not set a default --table value, the table name is derived from the CSV file.

Development

Install from your local repo

pip install -e .

Testing

To delete a test table, use bq:

bq rm -f -t  PROJECT_ID:DATASET_ID.TABLE_NAME

You can run the module directly when working on a new feature or fixing a bug:

python -m bqcsv.cli config set --project PROJECT_ID --dataset DATASET_ID --table TEST_TABLE_NAME

Releasing to PyPI

  1. Bump the version in both places (they must match):

    • pyproject.toml[project].version
    • bqcsv/__init__.py__version__
  2. Install build tools (one-time):

    pip install build twine
    
  3. Run tests and commit the version bump.

  4. Build the package:

    python -m build
    

    This creates dist/bqcsv-<version>.tar.gz and dist/bqcsv-<version>-py3-none-any.whl.

  5. Upload to PyPI:

    twine upload dist/*
    

    On first upload, create an account at pypi.org and use an API token as the password (__token__ as the username).

  6. Tag the release (optional but recommended):

    git tag v0.2.0
    git push origin v0.2.0
    

After publishing, users can install the new version with:

pip install --upgrade bqcsv

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

bqcsv-1.0.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

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

bqcsv-1.0.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file bqcsv-1.0.0.tar.gz.

File metadata

  • Download URL: bqcsv-1.0.0.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for bqcsv-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4130df0b948b864816b270ea34c83c18936f8605fd35bd397f8c033f0805369c
MD5 b06c9aafc7528ccf9e35ff4106e7b91f
BLAKE2b-256 bf1e1761b8157c72ad44b50a44730380f28fb72beed7f46ccf986ea0c23c6d18

See more details on using hashes here.

File details

Details for the file bqcsv-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: bqcsv-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for bqcsv-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d87ee33847aacbfc09f5ffb0d7930ff012e7aa4ae08f433a092d980ad36c90b
MD5 984bb8dcf8cff67f0e9ed0096b5dd095
BLAKE2b-256 225ee23a684a008830a78997f3156be3fa24e32ab24c97abd8d826c1753b9f80

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