|
| 1 | +# `dac`: Data as Code |
| 2 | + |
| 3 | +<div align="center"> |
| 4 | + <img src="img/motto.png" alt="drawing" width="450"/> |
| 5 | +</div> |
| 6 | + |
| 7 | +Data-as-Code (DaC) `dac` is a tool that supports the distribution of data as (python) code. |
| 8 | + |
| 9 | +<div align="center"> |
| 10 | + <img src="img/logo.jpg" alt="drawing" width="250"/> |
| 11 | +</div> |
| 12 | + |
| 13 | +## How will the Data Scientists use a DaC package? |
| 14 | + |
| 15 | +Say that the Data Engineers prepared the `demo-data` as code for you. Then you will install the code in your environment |
| 16 | +```sh |
| 17 | +python -m pip install demo-data |
| 18 | +``` |
| 19 | +and then you will be able to access the data simply with |
| 20 | +```python |
| 21 | +from demo_data import load |
| 22 | + |
| 23 | +data = load() |
| 24 | +``` |
| 25 | + |
| 26 | +Data can be in any format. There is no constraint of any kind. |
| 27 | + |
| 28 | +Not only accessing data will be this easy but, depending on how data were prepared, you may also have access to useful metadata. How? |
| 29 | +```python |
| 30 | +from demo_data import Schema |
| 31 | +``` |
| 32 | + |
| 33 | +With the schema you could, for example |
| 34 | + |
| 35 | +* access the column names (e.g. `Schema.my_column`) |
| 36 | +* unit test your functions by getting a data example with `Schema.example()` |
| 37 | + |
| 38 | +## How can a Data Engineer provide a DaC python package? |
| 39 | + |
| 40 | +Install this library |
| 41 | +```sh |
| 42 | +python -m pip install dac |
| 43 | +``` |
| 44 | +and use the command `dac pack` (run `dac pack --help` for detailed instructions). |
| 45 | + |
| 46 | +On a high level, the most important elements you must provide are: |
| 47 | + |
| 48 | +* python code to load the data |
| 49 | +* a `Schema` class that at very least contains a `validate` method, but possibly also |
| 50 | + |
| 51 | + - data field names (column names, if data is tabular) |
| 52 | + - an `example` method |
| 53 | + |
| 54 | +* python dependencies |
| 55 | + |
| 56 | +!!! hint "Use `pandera` to define the Schema" |
| 57 | + |
| 58 | + If the data type you are using is supported by [`pandera`](https://pandera.readthedocs.io/en/stable/index.html) consider using a [`DataFrameModel`](https://pandera.readthedocs.io/en/stable/dataframe_models.html) to define the Schema. |
| 59 | + |
| 60 | + |
| 61 | +## What are the advantages of distributing data in this way? |
| 62 | + |
| 63 | +* The code needed to load the data, the data source, and locations are abstracted away from the user. |
| 64 | + This mean that the data engineer can start from local files, transition to SQL database, cloud file storage, or kafka topic, without having the user to notice it or need to adapt its code. |
| 65 | + |
| 66 | +* *If you provide data field names in `Schema`* (e.g. `Schema.column_1`), the user code will not contain hard-coded column names, and changes in data source field names won't impact the user. |
| 67 | + |
| 68 | +* *If you provide the `Schema.example` method*, users will be able to build robust code by writing unit testing for their functions effortlessly. |
| 69 | + |
| 70 | +* Semantic versioning can be used to communicate significant changes: |
| 71 | + |
| 72 | + * a patch update corresponds to a fix in the data: its intended content is unchanged |
| 73 | + * a minor update corresponds to a change in the data that does not break the schema |
| 74 | + * a major update corresponds to a change in the schema, or any other breaking change |
| 75 | + |
| 76 | + In this way data pipelines can subscribe to the appropriate updates. Furthermore, it will be easy to keep releasing data updates maintaining retro-compatibility (one can keep deploying `1.X.Y` updates even after version `2` has been rolled-out). |
| 77 | + |
| 78 | +* Description of the data and columns can be included in the schema, and will therefore reach the user together with the data. |
| 79 | + |
| 80 | +* Users will always know where to look for data: the PyPi index. |
0 commit comments