基于Polars.rs的数据工程框架
项目描述
Datasaurus是一个用Python 3.8、3.9、3.10和3.11编写的数据工程框架
它基于Polars,并深受Django的影响。
Datasaurus提供了一个具有丰富功能和强大能力的框架,可以帮助您编写数据管道、ETL或数据处理程序。
文档 (待办事项)
它支持
- ✅ 完全支持读写操作。
- ⭕ 尚未实现,但将实现。
- 💀 近期内不会实现。
存储
- Sqlite ✅
- PostgresSQL ✅
- MySQL ✅
- Mariadb ✅
- 本地存储 ✅
- Azure blob存储 ⭕
- AWS S3 ⭕
格式
- CSV ✅
- JSON ✅
- PARQUET ✅
- EXCEL ✅
- AVRO ✅
- TSV ⭕
- SQL ⭕ (如SQL插入)
功能
- Delta表格 ⭕
- 字段验证 ⭕
简单示例
# 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'
我们可以通过'Model.df'访问原始的Polars数据框,它是懒加载的,这意味着只有在访问属性时才会加载数据。
>>> 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   │
└─────┴────────────────────┴──────────────────────────┴─────┘
我们现在可以创建一个新模型,其数据来自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:
        recalculate = 'if_no_data_in_storage'
        storage = ProfilesData
        table_name = 'PROFILE_FEMALES'
瞧!列将自动从列定义(id、profile_id和email)中选择。
如果我们现在调用
FemaleProfiles.df
它将检查数据帧是否存在于存储中,如果不存在,它将再次从 calculate_data 计算,并将其保存到存储中,此参数也可以设置为 '总是'。
您还可以将数据移动到不同的环境或存储,这使得更改格式或移动数据变得容易
FemaleProfiles.save(to=ProfilesData.live)
有效地将数据从 SQLITE (开发) 移动到 PostgreSQL (实时)
# 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)
          项目详情
下载文件
下载您平台上的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源分布
         datasaurus-0.0.2.dev4.tar.gz  (16.9 kB 查看散列)
      
    构建分布
         datasaurus-0.0.2.dev4-py3-none-any.whl  (20.0 kB 查看散列)
      
    
    
       关闭
    
      
        
    
    
  
datasaurus-0.0.2.dev4.tar.gz 的散列
| 算法 | 散列摘要 | |
|---|---|---|
| SHA256 | c8dd2a76fb6d52049232782ec575d2d53f634095478781a4a13c3793ec8a322a | |
| MD5 | 34308388f237ef34c6be5d64ca17c588 | |
| BLAKE2b-256 | 34e537f1adf2e208b1a93e60d29c2b22ba4b4eb121850c8c0dab77319f7c9d46 | 
    
       关闭
    
      
        
    
    
  
datasaurus-0.0.2.dev4-py3-none-any.whl 的散列
| 算法 | 散列摘要 | |
|---|---|---|
| SHA256 | 9e37584a072adf1184b546fe4f0a66dd13dd55ccaed6ef89102fdd609f780ce7 | |
| MD5 | 614abde226269b643c3a1531860ebce9 | |
| BLAKE2b-256 | a9cf9a68b4764c1a2df2668e8d8141c614654d45a3d55d8ee8f9ceeca03e74f3 |