Skip to main content

Loading Data from Aladtec to PostgreSQL Using dlt in Python

Need help deploying these pipelines, or figuring out how to run them in your data stack?

Join our Slack community or book a call with our support engineer Violetta.

Aladtec is a robust scheduling and workforce management system designed for public safety and healthcare organizations. It helps streamline employee scheduling, manage shift trades, and track work hours efficiently. This guide covers how to load data from Aladtec to PostgreSQL using the open-source Python library dlt. PostgreSQL is a powerful, open-source object-relational database system that extends the SQL language with many features for safely storing and scaling complex data workloads. By integrating Aladtec with PostgreSQL through dlt, organizations can optimize staffing, reduce scheduling conflicts, and ensure compliance with labor laws while benefiting from efficient data management and reporting. For more information on Aladtec, visit aladtec.com.

dlt Key Features

  • PostgreSQL as a Destination: Learn how to set up and configure PostgreSQL as a destination for your dlt pipeline. Read more
  • Governance in dlt Pipelines: Understand how dlt pipelines support robust governance through metadata utilization, schema enforcement, and schema change alerts. Read more
  • Data Types Supported by dlt: Explore the various data types that dlt supports, from text and double to complex and wei. Read more
  • Authentication Types for Snowflake: Discover the different authentication methods supported by Snowflake as a destination in dlt, including password, key pair, and external authentication. Read more
  • Extracting Data with dlt: Learn how to extract data efficiently using dlt's features like iterators, chunking, and parallelization. Read more

Getting started with your pipeline locally

OpenAPI Source Generator dlt-init-openapi

This walkthrough makes use of the dlt-init-openapi generator cli tool. You can read more about it here. The code generated by this tool uses the dlt rest_api verified source, docs for this are here.

0. Prerequisites

dlt and dlt-init-openapi requires Python 3.9 or higher. Additionally, you need to have the pip package manager installed, and we recommend using a virtual environment to manage your dependencies. You can learn more about preparing your computer for dlt in our installation reference.

1. Install dlt and dlt-init-openapi

First you need to install the dlt-init-openapi cli tool.

pip install dlt-init-openapi

The dlt-init-openapi cli is a powerful generator which you can use to turn any OpenAPI spec into a dlt source to ingest data from that api. The quality of the generator source is dependent on how well the API is designed and how accurate the OpenAPI spec you are using is. You may need to make tweaks to the generated code, you can learn more about this here.

# generate pipeline
# NOTE: add_limit adds a global limit, you can remove this later
# NOTE: you will need to select which endpoints to render, you
# can just hit Enter and all will be rendered.
dlt-init-openapi aladtec --url https://raw.githubusercontent.com/dlt-hub/openapi-specs/main/open_api_specs/Business/aladtec.yaml --global-limit 2
cd aladtec_pipeline
# install generated requirements
pip install -r requirements.txt

The last command will install the required dependencies for your pipeline. The dependencies are listed in the requirements.txt:

dlt>=0.4.12

You now have the following folder structure in your project:

aladtec_pipeline/
├── .dlt/
│ ├── config.toml # configs for your pipeline
│ └── secrets.toml # secrets for your pipeline
├── rest_api/ # The rest api verified source
│ └── ...
├── aladtec/
│ └── __init__.py # TODO: possibly tweak this file
├── aladtec_pipeline.py # your main pipeline script
├── requirements.txt # dependencies for your pipeline
└── .gitignore # ignore files for git (not required)

1.1. Tweak aladtec/__init__.py

This file contains the generated configuration of your rest_api. You can continue with the next steps and leave it as is, but you might want to come back here and make adjustments if you need your rest_api source set up in a different way. The generated file for the aladtec source will look like this:

Click to view full file (380 lines)

from typing import List

import dlt
from dlt.extract.source import DltResource
from rest_api import rest_api_source
from rest_api.typing import RESTAPIConfig


@dlt.source(name="aladtec_source", max_table_nesting=2)
def aladtec_source(
token: str = dlt.secrets.value,
base_url: str = dlt.config.value,
) -> List[DltResource]:

# source configuration
source_config: RESTAPIConfig = {
"client": {
"base_url": base_url,
"auth": {

"type": "bearer",
"token": token,

},
"paginator": {
"type":
"offset",
"limit":
100,
"offset_param":
"offset",
"limit_param":
"limit",
"total_path":
"",
"maximum_offset":
20,
},
},
"resources":
[
# Returns a list of all accrual banks.
{
"name": "accrual_bank",
"table_name": "accrual_bank",
"endpoint": {
"data_selector": "data",
"path": "/accrual-banks",
}
},
# Returns Member Availability for the requested date/time range.
{
"name": "availability",
"table_name": "availability",
"endpoint": {
"data_selector": "data",
"path": "/availability",
"params": {
"range_start_datetime": "FILL_ME_IN", # TODO: fill in required query parameter
"range_stop_datetime": "FILL_ME_IN", # TODO: fill in required query parameter

},
}
},
# Returns the number of hours in each specified accrual bank for a list of provided members.
{
"name": "balance",
"table_name": "balance",
"endpoint": {
"data_selector": "data",
"path": "/accrual-banks/balances",
"params": {
"member_ids": "FILL_ME_IN", # TODO: fill in required query parameter
"accrual_bank_ids": "FILL_ME_IN", # TODO: fill in required query parameter

},
}
},
# Members clocked in at the time of the request.
{
"name": "clocked_in_member",
"table_name": "clocked_in_member",
"endpoint": {
"data_selector": "data",
"path": "/time-clock-time/clocked-in-members",
}
},
# Returns a list of configuration settings.
{
"name": "configuration",
"table_name": "configuration",
"endpoint": {
"data_selector": "$",
"path": "/configuration",
}
},
# Returns all customer created Member Database attribute definitions.
{
"name": "custom_attribute",
"table_name": "custom_attribute",
"endpoint": {
"data_selector": "data",
"path": "/members/custom-attributes",
}
},
# Returns all employee types. These can be customized per Aladtec system. Examples: part time, full time, volunteer.
{
"name": "employee_type",
"table_name": "employee_type",
"endpoint": {
"data_selector": "data",
"path": "/members/employee-types",
}
},
# Events for requested date/time range.
{
"name": "event",
"table_name": "event",
"endpoint": {
"data_selector": "data",
"path": "/events",
"params": {
"range_start_datetime": "FILL_ME_IN", # TODO: fill in required query parameter
"range_stop_datetime": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "daily_split_time": "OPTIONAL_CONFIG",

},
}
},
# Returns extra hours ranges for a specified period of time in the past.
{
"name": "extra_hour",
"table_name": "extra_hour",
"endpoint": {
"data_selector": "data",
"path": "/extra-hours",
"params": {
"range_start_datetime": "FILL_ME_IN", # TODO: fill in required query parameter
"range_stop_datetime": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "schedule_ids": "OPTIONAL_CONFIG",
# "member_ids": "OPTIONAL_CONFIG",
# "position_qualification_ids": "OPTIONAL_CONFIG",
# "time_type_ids": "OPTIONAL_CONFIG",
# "statuses": "approved",
# "daily_split_time": "OPTIONAL_CONFIG",

},
}
},
# Returns a list of unique, active Kiosks used to clock in and out.
{
"name": "kiosk",
"table_name": "kiosk",
"primary_key": "kiosk_id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/time-clock/kiosks",
}
},
# Returns members and the members' associated Member Database attributes. Attributes must be accessible through the API or the value will be null. Contact Aladtec Support (support@aladtec.com, 888.749.5550) to make attributes accessible through the API.
{
"name": "member",
"table_name": "member",
"primary_key": "member_id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/members",
"params": {
# the parameters below can optionally be configured
# "member_ids": "OPTIONAL_CONFIG",
# "include_inactive": "false",
# "attribute_ids": "OPTIONAL_CONFIG",

},
}
},
# Schedule and position for each member scheduled at the time of the request.
{
"name": "members_scheduled_now",
"table_name": "members_scheduled_now",
"endpoint": {
"data_selector": "data",
"path": "/scheduled-time/members-scheduled-now",
"params": {
# the parameters below can optionally be configured
# "schedule_ids": "OPTIONAL_CONFIG",

},
}
},
# Returns Schedule Notes grouped by calendar date. Up to one year can be retrieved in a single request.
{
"name": "note",
"table_name": "note",
"endpoint": {
"data_selector": "data",
"path": "/scheduled-time/notes",
"params": {
"range_start_date": "FILL_ME_IN", # TODO: fill in required query parameter
"range_stop_date": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "schedule_ids": "OPTIONAL_CONFIG",

},
}
},
# Returns time ranges where no member is scheduled. Typically used for finding shifts needing coverage. Up to one month can be retrieved in a single request.
{
"name": "open_time",
"table_name": "open_time",
"endpoint": {
"data_selector": "data",
"path": "/scheduled-time/open-time",
"params": {
"range_start_datetime": "FILL_ME_IN", # TODO: fill in required query parameter
"range_stop_datetime": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "schedule_ids": "OPTIONAL_CONFIG",
# "position_ids": "OPTIONAL_CONFIG",
# "include_only_shift_time": "true",
# "daily_split_time": "OPTIONAL_CONFIG",

},
}
},
# Returns a list of unique, active Paycodes which can be applied to time clock time.
{
"name": "paycode",
"table_name": "paycode",
"primary_key": "paycode_id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/time-clock/paycodes",
}
},
# Runs the Payroll Report export. <strong>Pagination is required</strong> to export all records within the requested range.
{
"name": "payroll",
"table_name": "payroll",
"endpoint": {
"data_selector": "data",
"path": "/reports/payroll",
"params": {
"range_start_datetime": "FILL_ME_IN", # TODO: fill in required query parameter
"range_stop_datetime": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "member_ids": "OPTIONAL_CONFIG",
# "time_categories": "OPTIONAL_CONFIG",
# "next_token": "OPTIONAL_CONFIG",

},
}
},
# Returns a list of unique position qualifications.
{
"name": "position_qualification",
"table_name": "position_qualification",
"endpoint": {
"data_selector": "data",
"path": "/schedules/position-qualifications",
}
},
# Schedule configuration defined in an Aladtec system. Data is sorted by the order defined on the Setup -> Schedules page.
{
"name": "schedule",
"table_name": "schedule",
"primary_key": "schedule_id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "data",
"path": "/schedules",
"params": {
# the parameters below can optionally be configured
# "include_archived": "false",

},
}
},
# Returns scheduled time ranges for a specified period of time
{
"name": "scheduled_time",
"table_name": "scheduled_time",
"endpoint": {
"data_selector": "data",
"path": "/scheduled-time",
"params": {
"range_start_datetime": "FILL_ME_IN", # TODO: fill in required query parameter
"range_stop_datetime": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "schedule_ids": "OPTIONAL_CONFIG",
# "member_ids": "OPTIONAL_CONFIG",
# "position_ids": "OPTIONAL_CONFIG",
# "time_type_ids": "OPTIONAL_CONFIG",
# "daily_split_time": "OPTIONAL_CONFIG",

},
}
},
# Shift Labels for requested date range.
{
"name": "shift_label",
"table_name": "shift_label",
"endpoint": {
"data_selector": "data",
"path": "/shift-labels",
"params": {
"range_start_date": "FILL_ME_IN", # TODO: fill in required query parameter
"range_stop_date": "FILL_ME_IN", # TODO: fill in required query parameter

},
}
},
# Time Clock records for the requested date/time range. If a member is clocked in at the time of the request, the time clock record will be excluded.
{
"name": "time_clock_time",
"table_name": "time_clock_time",
"endpoint": {
"data_selector": "data",
"path": "/time-clock-time",
"params": {
"range_start_datetime": "FILL_ME_IN", # TODO: fill in required query parameter
"range_stop_datetime": "FILL_ME_IN", # TODO: fill in required query parameter

},
}
},
# Approved and pending Time Off ranges for the requested date/time range. Note: By default, only approved Time Off ranges are included in the response.
{
"name": "time_off",
"table_name": "time_off",
"endpoint": {
"data_selector": "data",
"path": "/time-off",
"params": {
"range_start_datetime": "FILL_ME_IN", # TODO: fill in required query parameter
"range_stop_datetime": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "statuses": "approved",
# "daily_split_time": "OPTIONAL_CONFIG",

},
}
},
# Returns a list of unique Time Types which can be applied to scheduled time.
{
"name": "time_type",
"table_name": "time_type",
"endpoint": {
"data_selector": "data",
"path": "/time-types",
}
},
# Returns all active Time Off Types.
{
"name": "type",
"table_name": "type",
"endpoint": {
"data_selector": "data",
"path": "/time-off/types",
}
},
# Returns all work groups. Work groups are used for putting members into groups if they follow the same schedule and work limit rules. Work groups can be customized per Aladtec system.
{
"name": "work_group",
"table_name": "work_group",
"endpoint": {
"data_selector": "data",
"path": "/work-groups",
}
},
]
}

return rest_api_source(source_config)

2. Configuring your source and destination credentials

info

dlt-init-openapi will try to detect which authentication mechanism (if any) is used by the API in question and add a placeholder in your secrets.toml.

  • If you know your API needs authentication, but none was detected, you can learn more about adding authentication to the rest_api here.
  • OAuth detection currently is not supported, but you can supply your own authentication mechanism as outlined here.

The dlt cli will have created a .dlt directory in your project folder. This directory contains a config.toml file and a secrets.toml file that you can use to configure your pipeline. The automatically created version of these files look like this:

generated config.toml


[runtime]
log_level="INFO"

[sources.aladtec]
# Base URL for the API
base_url = "https://..." # Replace with API base URL

generated secrets.toml


[sources.aladtec]
# secrets for your aladtec source
token = "FILL ME OUT" # TODO: fill in your credentials

2.1. Adjust the generated code to your usecase

Further help setting up your source and destinations

At this time, the dlt-init-openapi cli tool will always create pipelines that load to a local duckdb instance. Switching to a different destination is trivial, all you need to do is change the destination parameter in aladtec_pipeline.py to postgres and supply the credentials as outlined in the destination doc linked below.

  • Read more about setting up the rest_api source in our docs.
  • Read more about setting up the PostgreSQL destination in our docs.

3. Running your pipeline for the first time

The dlt cli has also created a main pipeline script for you at aladtec_pipeline.py, as well as a folder aladtec that contains additional python files for your source. These files are your local copies which you can modify to fit your needs. In some cases you may find that you only need to do small changes to your pipelines or add some configurations, in other cases these files can serve as a working starting point for your code, but will need to be adjusted to do what you need them to do.

The main pipeline script will look something like this:


import dlt

from aladtec import aladtec_source


if __name__ == "__main__":
pipeline = dlt.pipeline(
pipeline_name="aladtec_pipeline",
destination='duckdb',
dataset_name="aladtec_data",
progress="log",
export_schema_path="schemas/export"
)
source = aladtec_source()
info = pipeline.run(source)
print(info)

Provided you have set up your credentials, you can run your pipeline like a regular python script with the following command:

python aladtec_pipeline.py

4. Inspecting your load result

You can now inspect the state of your pipeline with the dlt cli:

dlt pipeline aladtec_pipeline info

You can also use streamlit to inspect the contents of your PostgreSQL destination for this:

# install streamlit
pip install streamlit
# run the streamlit app for your pipeline with the dlt cli:
dlt pipeline aladtec_pipeline show

5. Next steps to get your pipeline running in production

One of the beauties of dlt is, that we are just a plain Python library, so you can run your pipeline in any environment that supports Python >= 3.8. We have a couple of helpers and guides in our docs to get you there:

The Deploy section will show you how to deploy your pipeline to

  • Deploy with Github Actions: Learn how to deploy your pipeline using Github Actions.
  • Deploy with Airflow and Google Composer: Follow the guide to deploy a pipeline with Airflow and Google Composer.
  • Deploy with Google Cloud Functions: Step-by-step instructions to deploy using Google Cloud Functions.
  • Other Deployment Methods: Explore various other methods to deploy your pipeline here.

The running in production section will teach you about:

  • How to Monitor your pipeline: Learn how to effectively monitor your dlt pipeline in production by setting up appropriate monitoring mechanisms. How to Monitor your pipeline
  • Set up alerts: Ensure you are promptly notified of any issues or anomalies in your dlt pipeline by configuring alerts. Set up alerts
  • And set up tracing: Implement tracing to get detailed insights into the execution of your dlt pipeline, helping you diagnose and troubleshoot problems efficiently. And set up tracing

Available Sources and Resources

For this verified source the following sources and resources are available

Source Aladtec

Aladtec source for workforce management data including schedules, time clocks, payroll, and employee details.

Resource NameWrite DispositionDescription
time_clock_timeappendTracks the time entries for employees clocking in and out.
time_offappendManages employee time-off requests and approvals.
availabilityappendRecords the availability of employees for scheduling purposes.
position_qualificationappendDetails the qualifications required for specific positions.
scheduleappendContains the scheduling information for all employees.
clocked_in_memberappendLists employees currently clocked in.
noteappendStores notes related to scheduling and workforce management.
open_timeappendTracks open time slots that need to be filled.
accrual_bankappendManages the accruals of employee benefits like vacation or sick time.
payrollappendContains payroll-related data for employees.
work_groupappendDefines groups of employees working together.
extra_hourappendTracks extra hours worked by employees.
members_scheduled_nowappendLists members who are currently scheduled to work.
eventappendRecords events related to scheduling and workforce management.
time_typeappendCategorizes different types of time entries (e.g., regular, overtime).
kioskappendManages data related to kiosk interactions for clocking in/out.
paycodeappendDefines pay codes used in payroll processing.
scheduled_timeappendContains details of scheduled work times for employees.
shift_labelappendLabels used to categorize different shifts.
custom_attributeappendStores custom attributes for employees or scheduling.
balanceappendTracks the balance of various accruals for employees.
typeappendDefines different types of entities within the system.
employee_typeappendCategorizes employees by type (e.g., full-time, part-time).
configurationappendStores system configuration settings.
memberappendContains detailed information about each employee.

Additional pipeline guides

This demo works on codespaces. Codespaces is a development environment available for free to anyone with a Github account. You'll be asked to fork the demo repository and from there the README guides you with further steps.
The demo uses the Continue VSCode extension.

Off to codespaces!

DHelp

Ask a question

Welcome to "Codex Central", your next-gen help center, driven by OpenAI's GPT-4 model. It's more than just a forum or a FAQ hub – it's a dynamic knowledge base where coders can find AI-assisted solutions to their pressing problems. With GPT-4's powerful comprehension and predictive abilities, Codex Central provides instantaneous issue resolution, insightful debugging, and personalized guidance. Get your code running smoothly with the unparalleled support at Codex Central - coding help reimagined with AI prowess.