Skip to main content

A python client for typed interactions with the Dayforce API.

Project description

dayforce-client

PyPI version PyPI - Status Build Status PyPI - Python Version PyPI - License

dayforce-client is a python SDK for interfacing with the Dayforce REST API and SFTP server.

Installation

$ pip3 install dayforce-client

Basic Usage (Rest API)

The main interface to the Dayforce REST API is the Dayforce class. You can instantiate the Dayforce class by supplying a few authentication and configuration arguments:

import os

from dayforce_client.client import Dayforce

DAYFORCE_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)

All get_ methods on the Dayforce class will return a DayforceReponse object. A DayforceReponse object contains the Dayforce instance 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/12345
200
True
0:00:00.550066

Query Parameters

Certain 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=WorkAssignments

Accessing Response Content

Response contents can accessed using .get() syntax:

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

Pagination

Responses can also optionally be paginated using iteration syntax:

for page in df.get_employee_raw_punches():
  for raw_punch in page.get("Data"):
    print(raw_punch)

Yielding Resource Records

Optionally, you can use the DayforceResponse .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 corresponding DayforceResponse instance:

for page, employee in df.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()

Using disable_host_key_checking is discouraged, however. Instead, use ssh-keyscan to retrieve a known-good key (better yet, see if Dayforce will provide it to you!) and pass it in to the construtor.

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()

Batch Imports

Dayforce 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.

from dayforce import DayforceSFTP, ImportError, ImportPending

client = DayforceSFTP(hostname=...)
with client.connect():
  batch_token = client.put_import('./local/path/to/batch-20191225T000000.csv', type='KpiTargetImport')
  while True:
    try:
      client.raise_for_import_status(batch_token)
      print('batch import succeeded')
      break
    except ImportPending e:
      sleep 10
      continue
    except ImportError e:
      print('batch import failed')
      break

Development

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dayforce_client-0.2.2.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

dayforce_client-0.2.2-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file dayforce_client-0.2.2.tar.gz.

File metadata

  • Download URL: dayforce_client-0.2.2.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.2

File hashes

Hashes for dayforce_client-0.2.2.tar.gz
Algorithm Hash digest
SHA256 b9e0e12ca2905e045d30d7ab7d5ed1820adf43a5a83830da7a8e339f99bd9a66
MD5 203c023c81ba2be89b614a21462e6e7f
BLAKE2b-256 00d8cb29e19ee70b286eafb61f2014e51653c9a1b137f77a522a7774b05c23f8

See more details on using hashes here.

Provenance

File details

Details for the file dayforce_client-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: dayforce_client-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.2

File hashes

Hashes for dayforce_client-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 94d5d498dd33e3fdbbc9135cf829347a38c808d492d7a8409d710fd9059430fe
MD5 0b2a9c72452d5fd3e7da993c5d8b5cfb
BLAKE2b-256 2c83fed735bfb72e3241ad5356d69e4cc0794e96a93a4f98a503cb0e4db1e499

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page