A Python script to bulk import CSV files into Google Sheets with support for Korean text and robust error handling.
- Bulk import of CSV files to Google Sheets
- Support for Korean text (UTF-8, CP949 encoding)
- Automatic rate limiting and retry mechanism
- Secure credential handling
- Progress tracking with emoji indicators
- Detailed logging
- Clone the repository:
git clone <your-repo-url>cd<repo-directory>- Create a virtual environment and install dependencies:
python3 -m venv venv
source venv/bin/activate
python -m pip install -r requirements.txtSet up Google Sheets API:
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the Google Sheets API and Google Drive API
- Create credentials (OAuth 2.0 Client ID)
- Download the credentials and save as
credentials.jsonin the project directory
Configure the script:
- Copy
config.template.pytoconfig.py - Update
TEMPLATE_SPREADSHEET_IDinconfig.pywith your template spreadsheet ID - Adjust other settings in
config.pyif needed
- Copy
Run these commands from the repository root:
venv/bin/python sheets_importer.pyBefore running:
- Place your CSV files in the
csv_filesdirectory. - Make sure
config.pyandcredentials.jsonexist (see Setup). - Follow the prompt to authenticate with Google, if needed, and enter a name for the new spreadsheet.
The saved login in token.pickle is reused on later runs.
The script will:
- Copy the configured template to a new spreadsheet
- Import each CSV file into a separate sheet
- Show progress with emoji indicators
- Log all operations to
import_log.txt
Alternatively, activate the environment first:
source venv/bin/activate
python sheets_importer.pyEdit config.py to customize:
TEMPLATE_SPREADSHEET_ID: ID of your template spreadsheetMAX_FILE_SIZE_MB: Maximum allowed CSV file sizeREQUEST_DELAY: Delay between API requestsFILE_DELAY: Delay between processing filesMAX_RETRIES: Maximum number of retry attempts
- Sensitive files (
credentials.json,token.pickle,config.py) are automatically excluded from git - Credentials are stored securely with appropriate file permissions
- OAuth 2.0 authentication is used for Google API access
- Console output shows progress with emoji indicators
- Detailed logs are saved to
import_log.txt - Different log levels for different types of messages
- Automatic retry for rate limit errors
- Multiple encoding support for CSV files
- Validation of file sizes and formats
- Detailed error messages and logging