Data Engineering framework based on Polars.rs
Project description
Datasaurus is a Data Engineering framework written in Python 3.7+
It is based in Polars and heavily influenced by Django.
Datasaurus offers an opinionated, feature-rich and powerful framework to help you write data pipelines, ETLs or data manipulation programs.
Documentation (TODO)
It supports:
- โ Fully support read/write operations.
- โญ Not yet but will be implemented.
- ๐ Won't be implemented in the near future.
Storages:
- Sqlite โ
- PostgresSQL โ
- MySQL โ
- Mariadb โ
- Local Storage โ
- Azure blob storage โญ
- AWS S3 โญ
Formats:
- CSV โ
- JSON โ
- PARQUET โ
- EXCEL โ
- AVRO โ
- TSV โญ
- SQL โญ (Like sql inserts)
Features:
- Delta Tables โญ
- Field validations โญ
Simple example
# settings.py
from datasaurus.core.storage import PostgresStorage, StorageGroup, SqliteStorage
from datasaurus.core.models import StringColumn, IntegerColumn
# We set the environment that will be used.
os.environ['DATASAURUS_ENVIRONMENT'] = 'dev'
class ProfilesData(StorageGroup):
dev = SqliteStorage(path='/data/data.sqlite')
live = PostgresStorage(username='user', password='user', host='localhost', database='postgres')
# models.py
from datasaurus.core.models import Model, StringColumn, IntegerColumn
class ProfileModel(Model):
id = IntegerColumn()
username = StringColumn()
mail = StringColumn()
sex = StringColumn()
class Meta:
storage = ProfilesData
table_name = 'PROFILE'
We can access the raw Polar's dataframe with 'Model.df', it's lazy, meaning it'll only load the data if we access the attribute.
>>> ProfileModel.df
shape: (100, 4)
โโโโโโโฌโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโ
โ id โ username โ mail โ sex โ
โ --- โ --- โ --- โ --- โ
โ i64 โ str โ str โ str โ
โโโโโโโชโโโโโโโโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโชโโโโโโก
โ 1 โ ehayes โ colleen63@hotmail.com โ F โ
โ 2 โ thompsondeborah โ judyortega@hotmail.com โ F โ
โ 3 โ orivera โ iperkins@hotmail.com โ F โ
โ 4 โ ychase โ sophia92@hotmail.com โ F โ
โ โฆ โ โฆ โ โฆ โ โฆ โ
โ 97 โ mary38 โ sylvia80@yahoo.com โ F โ
โ 98 โ charlessteven โ usmith@gmail.com โ F โ
โ 99 โ plee โ powens@hotmail.com โ F โ
โ 100 โ elliottchristopher โ wilsonbenjamin@yahoo.com โ M โ
โโโโโโโดโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโ
We could now create a new model whose data is created from ProfileModel
class FemaleProfiles(Model):
id = IntegerField()
profile_id = IntegerField()
mail = StringField()
def calculate_data(self):
return (
ProfileModel.df
.filter(ProfileModel.sex == 'F')
.with_row_count('new_id')
.with_columns(
pl.col('new_id')
)
.with_columns(
pl.col('id').alias('profile_id')
)
)
class Meta:
auto_select = True
recalculate = True
storage = ProfilesData
table_name = 'PROFILE_FEMALES'
Et voilรก! We can now create new dataframes from other dataframes,
If we now call:
FemaleProfiles.ensure_exists()
In this example, by just calling ensure_exists it will:
- Check if the table exists in 'dev' (sqlite).
- Read ProfileModel from the 'dev' (sqlite).
- Calculate the new data (calculate_data).
- Validate that the columns of the resulting dataframe matches of the model's (In this case it will auto_select).
- Write the table in 'dev' (sqlite), if the table does not exist, it'll create it.
You can even move data to different environments or storages, making it easy to change formats or move data around.
You could for example call:
FemaleProfiles.save(to=ProfilesData.live)
Effectively moving data from SQLITE (dev) to PostgreSQL (live),
# Can also change formats
FemaleProfiles.save(to=ProfilesData.otherenvironment, format=LocalFormat.JSON)
FemaleProfiles.save(to=ProfilesData.otherenvironment, format=LocalFormat.CSV)
FemaleProfiles.save(to=ProfilesData.otherenvironment, format=LocalFormat.PARQUET)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for datasaurus-0.0.1.dev2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d70491597698f82c5b42d990bef070096921d1658d24b2a518728a39536c561b |
|
MD5 | fa3361e283bc8a29d653896108aceadc |
|
BLAKE2b-256 | 80e2ce0d71dfd3bb9b08a6e09ab5b4da766bd89db3a503ad94c0d8c1a8707604 |