Upload a local CSV file to BigQuery using the bq CLI and your existing gcloud authentication.
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
No additional authentication is needed.
bqcsv uses your existing authentication via gcloud auth login.
- Python 3.10+
- Google Cloud SDK with
bqon yourPATH
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_rawThe --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 dataTo 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 showDefaults are stored in ~/.config/bqcsv/config.toml.
After you set your defaults, you can call bqcsv without arguments:
bqcsv data.csvIf you have not set a default --table value, the table name is derived from the CSV file.
pip install -e .To delete a test table, use bq:
bq rm -f -t PROJECT_ID:DATASET_ID.TABLE_NAMEYou can run the module directly when working on a new feature or fixing a bug:
python -m src.cli config set --project PROJECT_ID --dataset DATASET_ID --table TEST_TABLE_NAME-
Bump the version in both places (they must match):
pyproject.toml→[project].versionsrc/__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