Package: dayforce-client
dayforce-clientdayforce-client is a python SDK for interfacing with the Dayforce REST API and SFTP server.Installation$pip3installdayforce-clientBasic Usage (Rest API)The main interface to the Dayforce REST API is theDayforceclass. You can instantiate theDayforceclass by supplying a few authentication and configuration arguments:importosfromdayforce_client.clientimportDayforceDAYFORCE_USERNAME=os.environ["DAYFORCE_USERNAME"]DAYFORCE_PASSWORD=os.environ["DAYFORCE_PASSWORD"]DAYFORCE_CLIENT_NAMESPACE=os.environ["DAYFORCE_CLIENT_NAMESPACE"]df=Dayforce(username=DAYFORCE_USERNAME,password=DAYFORCE_PASSWORD,client_namespace=DAYFORCE_CLIENT_NAMESPACE)Allget_methods on theDayforceclass will return aDayforceReponseobject. ADayforceReponseobject contains theDayforceinstance used to make the call, the parameters used in the request, and the response received from the 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.550066Query ParametersCertain methods also accept keyword arguments that will be used as query parameters for the request:resp=df.get_employee_details(xrefcode='12345',expand='WorkAssignments')print(resp.resp.url)Output:https://usr57-services.dayforcehcm.com/Api/your-client-namespace/V1/Employees/12345?expand=WorkAssignmentsAccessing Response ContentResponse contents can accessed using.get()syntax:resp=df.get_employee_details(xrefcode='12345')print(resp.get("Data"))PaginationResponses can also optionally be paginated using iteration syntax:forpageindf.get_employee_raw_punches():forraw_punchinpage.get("Data"):print(raw_punch)Yielding Resource RecordsOptionally, you can use theDayforceResponse.yield_records()method to handle response pagination and yieliding resource records. The method will paginate the response and iterate through response content to yield single resource records for the given resource and the correspondingDayforceResponseinstance: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]>)Basic Usage (SFTP client)client=DayforceSFTP(hostname='foo01.dayforcehcm.com',username='mycompany',password='sekret',disable_host_key_checking=True,)client.connect()Usingdisable_host_key_checkingis discouraged, however. Instead, usessh-keyscanto retrieve a known-good key (better yet, see if Dayforce will provide it to you!) and pass it in to the construtor.ssh-keyscanfoo01.dayforcehcm.com# foo01.dayforcehcm.com:22 SSH-2.0-9.99 FlowSsh: Bitvise SSH Server (WinSSHD)foo01.dayforcehcm.comssh-rsaAAAAB3...snip...XYZclient=DayforceSFTP(hostname='foo01.dayforcehcm.com',username='mycompany',password='sekret',host_key='AAAAB3...snip...XYZ',)client.connect()Batch ImportsDayforce provides the ability to batch import data via SFTP. This client wraps up most of the business logic around this process, and exposes a simple, high-level 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')breakDevelopmentpython3-mvenvinstall.venvsource.venv/bin/activate
makedev_install
maketest