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
- Python 3.10+
- Google Cloud SDK with
bqon yourPATH
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
-
Bump the version in both places (they must match):
pyproject.toml→[project].versionbqcsv/__init__.py→__version__
-
Install build tools (one-time):
pip install build twine
-
Run tests and commit the version bump.
-
Build the package:
python -m build
This creates
dist/bqcsv-<version>.tar.gzanddist/bqcsv-<version>-py3-none-any.whl. -
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). -
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4130df0b948b864816b270ea34c83c18936f8605fd35bd397f8c033f0805369c
|
|
| MD5 |
b06c9aafc7528ccf9e35ff4106e7b91f
|
|
| BLAKE2b-256 |
bf1e1761b8157c72ad44b50a44730380f28fb72beed7f46ccf986ea0c23c6d18
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d87ee33847aacbfc09f5ffb0d7930ff012e7aa4ae08f433a092d980ad36c90b
|
|
| MD5 |
984bb8dcf8cff67f0e9ed0096b5dd095
|
|
| BLAKE2b-256 |
225ee23a684a008830a78997f3156be3fa24e32ab24c97abd8d826c1753b9f80
|