Quickstart

This page gives you all the information you need to get started validating your CSVs with CsvPath. It is super high-level and quick. You will want to go deeper on other pages later. We're going to do a trivial validation of a CSV file. Validating an Excel file would be essentially the same.

If you need help getting started with Python, try Python.org's intros. Starting with a project tool like Poetry or Jupyter Notebooks can also help.

PyPI and Github

The open source CsvPath Framework is available through PyPI as csvpath. The project is quite active. You should pin the version you use but update it regularly.

We use Poetry for our own development. If you choose Poetry, all you need to do is:

poetry new <<your project name>>
cd <<your project name>>
poetry add csvpath

If you prefer Pip, install CsvPath Framework with:

pip install csvpath

Have a look at the Github project for more details. You can read that site in parallel to this one.

Screenshot of the open source CsvPath Framework's GitHub page

Let's run something!

The worker class in CsvPath is unsurprisingly called CsvPath. For simple validation, it is all you need.

The quickest way to bootstrap a CsvPath Framework project is the command line interface (CLI). The CLI is a super simple tool that is great for fast no-code development. To try the CLI, skip over to Your First Validation, The Lazy Way.

To continue with the simplest possible Python, let's do a hello world.

Create a script file and import CsvPath:

Add CsvPath to your requirements.txt or dependency manger first, of course!
from csvpath import CsvPath

Create a test CSV file. Save it as trivial.csv or whatever name you like.

A trivial CSV file to do a simple intro validation using CsvPath Language

Make a csvpath. Also a trivial one, just to keep it simple.

A trivial CsvPath Language validation statement. This statement can validate a CSV or Excel file.
csvpath = """$trivial.csv[*][yes()]"""

This path says:

  • Open trivial.csv

  • Scan all the lines

  • Match every one of them

A screenshot of the Python to run the validation file. It is the same as the code below.

Here's everything:

from csvpath import CsvPath

path = """$trivial.csv[*][yes()]"""

cp = CsvPath()
cp.fast_forward(path)

if cp.is_valid:
    print("Totally valid!")
else:
    print("Not valid.")    

What does this script do?

  • Line 1: imports CsvPath so we can use it

  • Line 3: is our csvpath that we'll use to validate our test file, trivial.csv

  • Line 6: fast-forwards though the CSV file's lines. We could also step through them one by one, if we wanted to.

  • Line 8: checks if we consider the file valid. If the file didn't meet expectations our csvpath would have declared the file invalid using the fail() function.

When you run your script you should see something like:

A screenshot of what you should see when you run your validation.

Hello-world examples are never super impressive on their own. But you are now ready to dig in and see what CsvPath can really do.

Next, try Your First Validation, the Lazy Way. Also check out the How-tos section for more use cases and examples. If you'd like a helping hand, contact us!

Last updated