# Code guide Use Python 3.11 or later. Run these commands from the repository root. The core dependency versions match the local export environment. ```bash python -m venv .venv ``` Activate the environment, then install: ```bash python -m pip install -r requirements.txt ``` ## Files | File | Purpose | |---|---| | `export_sqlite_to_parquet.py` | Export all four source databases. Preserve every table and column. Read sources only. Resume with the same command and output folder. | | `../verify_export.py` | Check Parquet schemas, sizes, row counts, NULL statistics, and part ranges. | | `../query_spotify.py` | Create 13 DuckDB views over the local files. Run SQL without a second database copy. | | `example_queries.sql` | Query tracks, artists, albums, genres, and audio features. | | `audit_sqlite_space.py` | Count SQLite B-tree pages and estimate column sizes from samples. | | `benchmark_audio_compression.py` | Compare lossless encodings on 32 distributed audio-feature samples. | | `smoke_test_export.py` | Export, verify, and query two source rows per table. Check that source files did not change. | | `check_package.py` | Check code syntax, table configurations, cleared notebook outputs, and portable paths. | | `test_upload_guards.py` | Test dry-run behavior, checksum failures, file lists, and protection of existing repositories without network calls. | | `prepare_hf_card.py` | Generate the dataset card and 13 table configurations from the manifest and counts. | | `dataset_card_template.md` | Body template for the generated card. | | `prepare_release.py` | Stage a completed export with this release's code and docs. Generate SHA256 checksums. No upload. | | `hf_upload_supervisor.py` | Continue an upload in the background, retry interruptions, record progress, and verify remote hashes. | | `verify_cleanup.py` | Verify the complete remote release and source identities before local cleanup. | | `cleanup_after_upload.ps1` | Remove only the explicitly authorized local folders after verification and process exit. | | `test_cleanup_controller.py` | Test deletion gates and folder scope on disposable dummy files without network access. | | `../upload_dataset.py` | Check the release. Create and upload a public dataset only with `--publish`. | | `original/` | Supplied notebooks, Python, PowerShell, SQL, and dependency list. | ## Export from SQLite The input folder must contain: ```text spotify_clean_audio_features.sqlite3 spotify_clean_track_files.sqlite3 spotify_clean.sqlite3 spotify_tracks_ranking.sqlite3 ``` Use the supplied counts only for these exact source databases. Recompute the counts for different source files. Pass that new JSON file with `--source-counts`. The count file uses `File`, `Table`, and `Rows` fields. The exporter also checks source file size and modification time when resuming. ```bash python code/export_sqlite_to_parquet.py --source-dir SOURCE_SQLITE --output-dir NEW_PARQUET --work-dir work/export --workers 4 --level 9 python verify_export.py --data-dir NEW_PARQUET python query_spotify.py --data-dir NEW_PARQUET --sql "SELECT count(*) FROM tracks" ``` `SOURCE_SQLITE` and `NEW_PARQUET` are paths you supply. Use a new output folder. For a failed export, repeat the same command to resume. Finished parts are checked before they are reused. Do not edit source databases during export. The exporter uses bounded batches. `track_files` uses smaller batches because its rows are wider. Integer fields use int64. Measurements use float64. The `tempo` column is exported as float64 even though the SQLite declaration says INTEGER; the stored values contain fractions. Each part is read back before it is accepted. The manifest records source schema SQL, exact part checks, NULL counts, row ranges, and file sizes. Source indexes are recorded as SQL definitions, not Parquet index structures. The output preserves table values and row identity. It is not a byte-for-byte copy of the original SQLite files. ## Test and inspect storage Use a new empty folder for each sample or benchmark run. ```bash python code/smoke_test_export.py --source-dir SOURCE_SQLITE --work-dir work/smoke python code/check_package.py python code/test_upload_guards.py python code/audit_sqlite_space.py --database SOURCE_SQLITE/spotify_clean.sqlite3 --output work/sqlite_space_audit.json python code/benchmark_audio_compression.py --database SOURCE_SQLITE/spotify_clean_audio_features.sqlite3 --output-dir work/audio_benchmark ``` The benchmark's projected sizes are estimates. The completed export sizes in `manifest.json` are measured. The page audit reconciles its page count and reports column estimates from sampled records. It is not a general SQLite repair tool. ## Prepare another release Keep the code and docs from this repository as release assets. The following command combines those assets with a separately validated export: ```bash python code/prepare_release.py --compressed-dir NEW_PARQUET --output-dir NEW_RELEASE --repo-id USER/NEW_DATASET ``` The default uses hard links, so both folders must use the same filesystem. Hard links refer to the same stored bytes. Do not edit linked Parquet files. Use `--copy-data` for a separate copy or another drive. That needs space for the full data. Run local checks for the new package before publication. Regenerate the card or checksum inventory after editing the package: ```bash python code/prepare_hf_card.py --repo-id USER/NEW_DATASET python code/prepare_release.py --inventory-only . python upload_dataset.py ``` The checksum inventory excludes itself, caches, Python bytecode, virtual environments, the `work` folder, Git files, and local upload state. ## Publish when ready The uploader uses `huggingface_hub==2.2.0` and its resumable `upload_folder` pipeline. Use a separate virtual environment for these dependencies. The older large-folder path can resend completed files during commit. See the [official upload guide](https://huggingface.co/docs/huggingface_hub/guides/upload). Log in through the normal Hugging Face CLI if you are not already logged in. Do not put a token in a script or commit it to the repository. ```bash hf auth login python upload_dataset.py ``` The command above makes no network requests. It checks local paths, file sizes, file counts, and the inventory. To create the proposed public dataset and upload the exact listed files: ```bash python upload_dataset.py --publish ``` Publication checks every SHA256 checksum first. It then checks the logged-in account, creates a new public dataset, and uploads. It refuses to replace an existing dataset on a fresh run. To continue this same interrupted release: ```bash python upload_dataset.py --publish --resume ``` Keep `upload_state.json` and `.cache/huggingface` for resuming. They stay local. The uploader checks the expected remote file sizes after transfer. Data and code must not change between an initial attempt and its resume. ## Supplied code `original/aaspotify_count_all.ps1`, `original/aaspotify_sample.ps1`, and `original/aaspotify_build_md.ps1` use DuckDB's command-line program. Install `duckdb` on PATH. These scripts now accept source and output paths: ```powershell ./code/original/aaspotify_count_all.ps1 -SourceDir SOURCE_SQLITE -OutputDir work/sqlite_inspect ./code/original/aaspotify_build_md.ps1 -SourceDir SOURCE_SQLITE -OutputDir work/sqlite_inspect ``` The count operation reads all tables and can take time. The Markdown builder needs the generated `aaspotify_counts.json` in the same output folder. `aaspotify_sample.ps1` can make a sample without the counts file. `original/_1_.ipynb`, `original/_2_duckdb.ipynb`, `original/_2_duckdb.py`, and `original/Script.sql` are historical analysis code. Notebook output and run counts were cleared. Machine-specific script paths were replaced. The SQL and notebooks contain exploratory steps, including database writes. Review them and use working copies of the source files before running them. For those tools, install `code/original/requirements.txt`. The source `req.txt` is also retained. The historical notebooks have not been rerun end to end. The portable exporter, validation helper, query helper, and package checks are the supported path for this release.