{"id":6565,"library":"clevercsv","title":"CleverCSV","description":"CleverCSV is a Python package designed for robustly handling messy CSV files. It provides a drop-in replacement for the standard Python `csv` module, enhancing dialect detection capabilities to accurately parse files that often cause issues. It also includes a command-line interface for tasks like standardization and code generation. The library maintains an active development status, with several minor releases typically occurring each year.","status":"active","version":"0.8.4","language":"en","source_language":"en","source_url":"https://github.com/alan-turing-institute/CleverCSV","tags":["csv","data-parsing","dialect-detection","data-wrangling","file-io"],"install":[{"cmd":"pip install clevercsv","lang":"bash","label":"Core library"},{"cmd":"pip install clevercsv[full]","lang":"bash","label":"With CLI tools and optional dependencies (e.g., tabview)"}],"dependencies":[{"reason":"Required for functions like `read_dataframe` to load CSV data directly into a Pandas DataFrame.","package":"pandas","optional":true},{"reason":"Required for the `clevercsv explore` command-line tool, which provides an interactive viewer.","package":"tabview","optional":true}],"imports":[{"note":"Commonly imported as a direct replacement for the built-in `csv` module.","symbol":"clevercsv","correct":"import clevercsv"},{"note":"CleverCSV provides a compatible `reader` object, often preferred for its improved dialect detection.","wrong":"import csv\nreader = csv.reader(file, dialect)","symbol":"reader","correct":"import clevercsv\nreader = clevercsv.reader(file, dialect)"},{"note":"A high-level function for automatically detecting dialect and encoding, returning data as a list of lists.","symbol":"read_table","correct":"import clevercsv\ntable = clevercsv.read_table('my_file.csv')"},{"note":"Automatically detects dialect and encoding, then uses Pandas to read into a DataFrame. Requires `pandas`.","symbol":"read_dataframe","correct":"import clevercsv\ndf = clevercsv.read_dataframe('my_file.csv')"}],"quickstart":{"code":"import clevercsv\nimport os\n\n# Create a dummy messy CSV file for demonstration\ncsv_content = 'col1;col2;col3\\nvalue1;\"value,2\";value3\\n4;5;6\\n'\nfile_path = 'messy_data.csv'\nwith open(file_path, 'w', newline='', encoding='utf-8') as f:\n    f.write(csv_content)\n\ntry:\n    # Use read_table to automatically detect the dialect and load the data\n    rows = clevercsv.read_table(file_path)\n    print(f\"Loaded {len(rows)} rows with detected dialect:\")\n    for row in rows:\n        print(row)\n\n    # Demonstrate drop-in replacement for standard csv module usage\n    with open(file_path, 'r', newline='') as csvfile:\n        # Sniff the dialect using CleverCSV's improved sniffer\n        dialect = clevercsv.Sniffer().sniff(csvfile.read(1024))\n        csvfile.seek(0)\n        reader = clevercsv.reader(csvfile, dialect)\n        sniffer_rows = list(reader)\n    print(f\"\\nLoaded {len(sniffer_rows)} rows using CleverCSV.Sniffer:\")\n    for row in sniffer_rows:\n        print(row)\n\nfinally:\n    # Clean up the dummy file\n    if os.path.exists(file_path):\n        os.remove(file_path)\n","lang":"python","description":"This quickstart demonstrates how to use CleverCSV to read a messy CSV file, automatically detecting its dialect, using both the high-level `read_table` function and by employing `clevercsv.Sniffer` as a drop-in replacement for the standard library's `csv.Sniffer`."},"warnings":[{"fix":"Ensure your Python environment is version 3.9 or newer. Upgrade Python if necessary.","message":"The minimum required Python version has been bumped. Version `0.8.1` required Python `>=3.8`, and the latest `0.8.4` requires Python `>=3.9`.","severity":"breaking","affected_versions":"0.8.1 and later"},{"fix":"If directly interacting with `ConsistencyDetector`, update your code to instantiate the `ConsistencyDetector` class and then call its methods (e.g., `detector = clevercsv.consistency.ConsistencyDetector()`).","message":"The internal `ConsistencyDetector` functionality was redesigned in `v0.8.0` from a direct function to a class. Direct calls to the old function signature will fail.","severity":"breaking","affected_versions":"0.8.0 and later"},{"fix":"For full functionality, especially if using the CLI `explore` command or `read_dataframe`, install the package using `pip install clevercsv[full]`.","message":"The `clevercsv explore` command-line tool and other advanced features like `read_dataframe` (which uses Pandas) rely on optional dependencies. If you install `clevercsv` without specifying `[full]`, these features might be unavailable or raise import errors.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}