{"id":27272,"library":"pycsvschema","title":"PyCSVSchema","description":"PyCSVSchema is a Python implementation of the CSV Schema specification (version 0.3). It allows you to validate CSV files against a schema defined in YAML or JSON. Currently at version 0.0.6, it is in early development with weekly commits.","status":"active","version":"0.0.6","language":"python","source_language":"en","source_url":"https://github.com/csv-schema/PyCSVSchema","tags":["csv","schema","validation","csv-schema"],"install":[{"cmd":"pip install pycsvschema","lang":"bash","label":"pip"}],"dependencies":null,"imports":[{"note":"CSVSchema is directly importable from the top-level package; the old import path was used in earlier versions.","wrong":"from pycsvschema.validator import CSVSchema","symbol":"CSVSchema","correct":"from pycsvschema import CSVSchema"},{"note":"ValidationError is re-exported from pycsvschema; older versions required importing from exceptions.","wrong":"from pycsvschema.exceptions import ValidationError","symbol":"ValidationError","correct":"from pycsvschema import ValidationError"}],"quickstart":{"code":"import yaml\nfrom pycsvschema import CSVSchema\n\nschema_yaml = \"\"\"\nfields:\n  - name: id\n    type: integer\n    constraints:\n      required: true\n  - name: name\n    type: string\n\"\"\"\nschema = yaml.safe_load(schema_yaml)\nvalidator = CSVSchema(schema)\n\nwith open('data.csv', 'r') as f:\n    errors = validator.validate(f)\n\nfor error in errors:\n    print(error)\n","lang":"python","description":"Load a schema from YAML, create a CSVSchema instance, and validate a CSV file."},"warnings":[{"fix":"Parse the schema using yaml.safe_load() or json.loads() before passing to CSVSchema.","message":"PyCSVSchema expects the schema in Python dict form (parsed from YAML/JSON), not a raw string. Passing a schema string directly will raise a TypeError.","severity":"gotcha","affected_versions":"all"},{"fix":"Use CSVSchema instead of CSVValidator. Change imports and constructor calls.","message":"In v0.0.6, the library switched from CSVValidator class to CSVSchema. Importing CSVValidator from pycsvschema no longer works.","severity":"breaking","affected_versions":">=0.0.6"},{"fix":"Use with open('file.csv') as f: validator.validate(f) instead of validator.validate('file.csv').","message":"Using 'validate()' with a file path string is deprecated; always pass a file object (opened via open()).","severity":"deprecated","affected_versions":">=0.0.5"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Parse the schema with yaml.safe_load(schema_string) or json.loads(schema_json) first.","cause":"Passed a schema string directly to CSVSchema instead of a dict.","error":"TypeError: string indices must be integers"},{"fix":"Use CSVSchema instead of CSVValidator.","cause":"CSVValidator was renamed to CSVSchema in v0.0.6.","error":"AttributeError: module 'pycsvschema' has no attribute 'CSVValidator'"},{"fix":"Open the file with open('data.csv') and pass the file object to validate().","cause":"You passed a file path string to validate(), which is deprecated and often fails due to cwd issues.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'data.csv'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}