Strapi is a headless CMS (Content Management System) that allows developers to create API-driven content management systems without having to write a lot of custom code.
Since Strapi's available endpoints vary based on your Strapi setup, ensure you recognize the ones you'll ingest to transfer data to your warehouse.
dlt verified source and
loads data using “Strapi API” to the destination of your choice.
Sources and resources that can be loaded using this verified source are:
|strapi_source||Retrieves data from Strapi|
Grab API token
- Log in to Strapi.
- Click ⚙️ in the sidebar.
- Go to API tokens under global settings.
- Create a new API token.
- Fill in Name, Description, and Duration.
- Choose a token type: Read Only, Full Access, or custom (with find and findOne selected).
- Save to view your API token.
- Copy it for DLT secrets setup.
Note: The Strapi UI, which is described here, might change. The full guide is available at this link.
Initialize the verified source
To get started with your data pipeline, follow these steps:
Enter the following command:
dlt init strapi duckdb
If you'd like to use a different destination, simply replace
duckdbwith the name of your preferred destination.
After running this command, a new directory will be created with the necessary files and configuration settings to get started.
For more information, read the Walkthrough: Add a verified source.
.dltfolder, there's a file called
secrets.toml. It's where you store sensitive information securely, like access tokens. Keep this file safe. Here's its format for service account authentication:
# put your secret values and credentials here. do not share this file and do not push it to github
api_secret_key = "api_secret_key" # please set me up!
domain = "domain" # please set me up!
api_secret_keywith the API token you copied above.
Strapi auto-generates the domain.
The domain is the URL opened in a new tab when you run Strapi, e.g., [my-strapi.up.your_app.app].
Finally, enter credentials for your chosen destination as per the docs.
For more information, read the General Usage: Credentials.
Run the pipeline
Before running the pipeline, ensure that you have installed all the necessary dependencies by running the command:
pip install -r requirements.txt
You're now ready to run the pipeline! To get started, run the following command:
In the provided script, we've included a list with one endpoint, "athletes." Simply add any other endpoints from your Strapi setup to this list in order to load them. Then, execute this file to initiate the data loading process.
Once the pipeline has finished running, you can verify that everything loaded correctly by using the following command:
dlt pipeline <pipeline_name> show
For example, the
pipeline_namefor the above pipeline example is
strapi, you may also use any custom name instead.
For more information, read the Walkthrough: Run a pipeline.
Sources and resources
This function retrives data from Strapi.
api_secret_key: str = dlt.secrets.value,
domain: str = dlt.secrets.value,
) -> Iterable[DltResource]:
endpoints: Collections to fetch data from.
api_secret_key: API secret key for authentication, defaults to dlt secrets.
domain: Strapi API domain name, defaults to dlt secrets.
Create your own pipeline
If you wish to create your own pipelines, you can leverage source and resource methods from this verified source.
Configure the pipeline by specifying the pipeline name, destination, and dataset as follows:
pipeline = dlt.pipeline(
pipeline_name="strapi", # Use a custom name if desired
destination="duckdb", # Choose the appropriate destination (e.g., duckdb, redshift, post)
dataset_name="strapi_data" # Use a custom name if desired
To load the specified endpoints:
endpoints = ["athletes"]
load_data = strapi_source(endpoints=endpoints)
load_info = pipeline.run(load_data)
# pretty print the information on data that was loaded
We loaded the "athletes" endpoint above, which can be customized to suit our specific requirements.