Python Starters
A few really basic scripts to get you started
The CsvPath library was build to be easy. You can do a lot with very little Python scaffolding. Let's look at some code. Obviously, you can do better and have more stringent requirements. But starting from a blank page is harder than editing.
Simplest CsvPath Runner Ever
The script above reads a file you give it as a command line argument. The file is a csvpath that must include the file it is being run against. It might look like this:
After parsing the csvpath the script fast-forwards through all CSV lines. Any print statements or other side effects happen, as you would expect, and you don't have to iterate or collect the lines. If your csvpath marks the file invalid you can see that on the is_valid
property of path
.
Iterating Matches
This script, like the first, takes a file path as a command line argument. In this case we are iterating on all the lines that match and printing them out.
A Multi-csvpath Starter
CsvPath AutoGen typically auto-generates multi-csvpath validations based on your example data. These require a CsvPaths
instance. Setting up CsvPaths is not very different.
In this case we are setting up a number of csvpath statements that live in a single file. They will run against a usage report CSV. We do fast_forward_paths
to run the csvpaths sequentially without collecting or iterating on the matched lines.
An Airflow Stub
There's nothing notable about this Airflow stub. To, I'm sure, nobody's surprise, the CsvPath library fits well in an Airflow solution. This code is just a placeholder for the awesome Airflow things you will do.
Last updated