大数据处理助手

planchet的Python项目详细描述


普朗切特

您的大型数据处理个人助理

CircleCIMaintainabilityTest CoverageLicense: MITDocumentation StatusContributors

关于

Planchet(发音为/plʌ̃ʃɛ/)是一种适合处理大型数据数组的数据包管理器 项目。它支持本机读写CSV和JSONL数据文件 并通过FastAPI服务向处理 数据。它是科学家和黑客的工具,而不是生产工具。在

工作原理

Planchet在一个简单的 通过控制数据的读写 反对处理。当你用Planchet创建一个工作时,你告诉 在哪里读,在哪里写,用什么类。接下来, 您(使用客户机或简单的HTTP请求)向服务请求n数据 项,您的过程在本地运行。当你的处理完成后, 它将这些项目送回Planchet,由他将它们写入磁盘。所有工作和 项目的服务和接收记录在Redis实例中,并具有持久性。 这样可以确保,如果停止处理,则只会丢失 没有发送回Planchet的数据。Planchet将自动恢复 作业和跳过已处理的项目。在

注意:Planchet在一个线程中运行,以避免多个线程的混乱 进程写入同一文件。在这件事解决之前(也许永远不会)你 注意不要太大 很小。在

diagram

阅读更多关于普兰切特的信息 documentation page。在

安装

Planchet有两个组件:服务和客户端。服务是 当客户机是一盏灯时,负责管理数据的核心 包装requests,使访问服务API更容易。在

服务

你可以使用这个回购协议,然后像这样开始交易:

git clone git@github.com:savkov/planchet.git
exportPLANCHET_REDIS_PWD=<some-password>
make install
make run-redis
make run

如果要在其他端口上运行Planchet,可以使用uvicorn 命令,但请注意,必须只使用一个worker。在

^{pr2}$

您也可以从git repo运行docker compose:

git clone git@github.com:savkov/planchet.git
exportPLANCHET_REDIS_PWD=<some-password>
docker-compose up

客户

pip install planchet

示例

在服务器上

在服务器上,我们需要安装Planchet并下载一些新闻标题数据 在可访问的目录中。然后我们把数据乘以1000倍 原来只有200行。别忘了在之前设置您的Redis密码 你要make install-redis!在

git clone https://github.com/savkov/planchet.git
cd planchet
mkdir data
wget https://raw.githubusercontent.com/explosion/prodigy-recipes/master/example-datasets/news_headlines.jsonl -O data/news_headlines.jsonl
python -c "news=open('data/news_headlines.jsonl').read();open('data/news_headlines.jsonl', 'w').write(''.join([news for _ in range(200)]))"exportPLANCHET_REDIS_PWD=<your-redis-password>
make install
make install-redis
make run

请注意,planchet将在主机上的端口5005上运行。在

在客户端

在客户端,我们需要安装Planchet客户端和spaCy。在

pip install planchet spacy tqdm
python -m spacy download en_core_web_sm
exportPLANCHET_REDIS_PWD=<your-redis-password>

然后我们在一个名为spacy_ner.py的文件中编写以下脚本,以确保 你填写占位符。在

fromplanchetimportPlanchetClientimportspacyfromtqdmimporttqdmnlp=spacy.load("en_core_web_sm")PLANCHET_HOST='localhost'# <--- CHANGE IF NEEDEDPLANCHET_PORT=5005url=f'http://{PLANCHET_HOST}:{PLANCHET_PORT}'client=PlanchetClient(url)job_name='spacy-ner-job'metadata={# NOTE: this assumes planchet has access to this path'input_file_path':'./data/news_headlines.jsonl','output_file_path':'./data/entities.jsonl'}# make sure you don't use the clean_start option hereclient.start_job(job_name,metadata,'JsonlReader',writer_name='JsonlWriter')# make sure the number of items is large enough to avoid blocking the servern_items=100headlines=client.get(job_name,n_items)whileheadlines:ents=[]print('Processing headlines batch...')forid_,itemintqdm(headlines):item['ents']=[ent.textforentinnlp(item['text']).ents]ents.append((id_,item))client.send(job_name,ents)headlines=client.get(job_name,n_items)

最后,我们想用8个进程进行一些并行处理。我们可以开始了 每个进程都是手动的,或者我们可以使用parallel工具来启动它们。在

seq -w 08| parallel python spacy_ner.py {}

贡献者

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java需要一种简单的方法来创建用于排序的comparator类   java getReadableDatabase和getWriteableDatabase无法解析   查找列表<Long>中与某个元素对应的所有索引的java方法   安卓将视图添加到ViewFlipper会导致java。StackOverflowerr语言   java根据它所包含的长“curTime”类字段将N的列表拆分为24(小时)   Android N中的Java8流API   自动生成Java策略文件的安全性   垃圾收集鼓励Java中的主要GC(但不是STW GC)   java如何检查UDP服务器上侦听的客户端数量   在前一台主机被Datastax Java驱动程序关闭后,Cassandra尝试重新连接到下一台主机   java如何使用Spring Boot创建部分代理   java是否有一个网站或资源可以完全比较EJB版本   java无需使用第三方库从gradle生成输出   继承由于这个多态性的基本示例中的语法有什么不同吗?(爪哇)   java字符串数组中的空字符串   java为什么CMS中的初始标记阶段是串行的   为什么Lucene有时与InChIKeys不匹配?   安卓通知Java应用程序数据库中的更改   java如何将单个json对象值解析为按钮   java打印堆栈将运行时错误跟踪到文件