用于与dayforceapi进行类型化交互的python客户机。

dayforce-client的Python项目详细描述


dayforce客户端

PyPI versionPyPI - StatusBuild StatusPyPI - Python VersionPyPI - License

dayforceclient是一个pythonsdk,用于与dayforcesrestapi和SFTP服务器接口。在

安装

$ pip3 install dayforce-client

基本用法(Rest API)

dayforcesrestapi的主接口是Dayforce类。您可以通过提供一些身份验证和配置参数来实例化Dayforce类:

^{pr2}$

Dayforce类上的所有get_方法都将返回一个DayforceReponse对象。DayforceReponse对象包含用于进行调用的Dayforce实例、请求中使用的参数以及从API接收的响应:

resp=df.get_employee_details(xrefcode='12345')print(resp.client)print(type(resp.client))print(resp.params)print(type(resp.resp))print(resp.resp.url)print(resp.resp.status_code)print(resp.resp.ok)print(resp.resp.elapsed)...Dayforce(username='your-username',client_namespace='your-client-namespace',dayforce_release=57,api_version='V1',url='https://usr57-services.dayforcehcm.com/Api/your-client-namespace/V1')<class'dayforce_client.client.Dayforce'>{}<class'requests.models.Response'>https://usr57-services.dayforcehcm.com/Api/your-client-namespace/V1/Employees/12345200True0:00:00.550066

查询参数

某些方法还接受将用作请求查询参数的关键字参数:

resp=df.get_employee_details(xrefcode='12345',expand='WorkAssignments')print(resp.resp.url)

输出:

https://usr57-services.dayforcehcm.com/Api/your-client-namespace/V1/Employees/12345?expand=WorkAssignments

访问响应内容

可以使用.get()语法访问响应内容:

resp=df.get_employee_details(xrefcode='12345')print(resp.get("Data"))

分页

还可以选择使用迭代语法对响应进行分页:

forpageindf.get_employee_raw_punches():forraw_punchinpage.get("Data"):print(raw_punch)

产出资源记录

或者,您可以使用DayforceResponse.yield_records()方法来处理响应分页和yieling资源记录。该方法将对响应进行分页并遍历响应内容,以生成给定资源和相应的DayforceResponse实例的单个资源记录:

forpage,employeeindf.get_employees().yield_records():print(employee)print(page)...{'XRefCode':'12345'}DayforceResponse(client=Dayforce(username='your-username',client_namespace='your-client-namespace',dayforce_release=57,api_version='V1',url='https://usr57-services.dayforcehcm.com/Api/your-client-namespace/V1'),params={},resp=<Response[200]>){'XRefCode':'67891'}DayforceResponse(client=Dayforce(username='your-username',client_namespace='your-client-namespace',dayforce_release=57,api_version='V1',url='https://usr57-services.dayforcehcm.com/Api/your-client-namespace/V1'),params={},resp=<Response[200]>)

基本用法(SFTP客户端)

client=DayforceSFTP(hostname='foo01.dayforcehcm.com',username='mycompany',password='sekret',disable_host_key_checking=True,)client.connect()

{12>但是不鼓励使用ssh-keyscan来检索已知的好密钥(更好的方法是,看看Dayforce是否会提供给您!)把它交给建筑工人。在

ssh-keyscan foo01.dayforcehcm.com
# foo01.dayforcehcm.com:22 SSH-2.0-9.99 FlowSsh: Bitvise SSH Server (WinSSHD)
foo01.dayforcehcm.com ssh-rsa AAAAB3...snip...XYZ
client=DayforceSFTP(hostname='foo01.dayforcehcm.com',username='mycompany',password='sekret',host_key='AAAAB3...snip...XYZ',)client.connect()

批量导入

提供通过dayp强制导入数据的功能。这个客户机封装了这个流程的大部分业务逻辑,并公开了一个简单的高级API。在

fromdayforceimportDayforceSFTP,ImportError,ImportPendingclient=DayforceSFTP(hostname=...)withclient.connect():batch_token=client.put_import('./local/path/to/batch-20191225T000000.csv',type='KpiTargetImport')whileTrue:try:client.raise_for_import_status(batch_token)print('batch import succeeded')breakexceptImportPendinge:sleep10continueexceptImportErrore:print('batch import failed')break

发展

python3 -m venv install .venv
source .venv/bin/activate
make dev_install
make test

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

推荐PyPI第三方库


热门话题
java如何在mongodb中获取用户有权访问的数据库列表?   基于契约和类不变量的java设计   java我的代码有什么问题,似乎是正确的,但事实并非如此   java Android初学者:布局按钮和文本   400错误Paypal令牌API与Java(HttpURLConnection)   为什么Java从socket中随机读取数据,而不是整个消息?   如果我调用scanner,我会扫描两次。先是下一个,然后是扫描仪。下一个   如果消息发送失败,java ActiveMQ/JMS不重试   java有没有类似于dynaTrace的开源框架?   java Android:获取zip中的文件数(使用存储卷/存储访问框架)   java无法将流图像解码为片段   java如何修复Jenkins插件中的“此位置的预期stackmap帧”   java如何使用javac编译器编译AndroidManifest。xml文件?