Building Solution
Prerequisites
- Access to a CDF Project.
- Know how to install and setup
Pythonusinguvandpyproject.toml. - Know how to use
gitfor version control. - Know how to use a terminal, so you can run
pygenfrom the command line to generate the SDK.
When you are ready to develop a solution based on a data model, you can use pygen to genrate a SDK that you check
into version history. This SDK can be used by the developer team to interact with CDF.
This pages shows the recommended project structure for a CDF SDK project.
Project Structure
The following is the recommended project structure for a CDF SDK project:
📦my_python_application
┣ 📂client - CDF SDK generated by pygen
┣ ┣ 📂_api
┣ ┣ 📂data_classes
┃ ┗ 📜__init__.py
┃ ┗ 📜_api_client.py
...
┣ 📜.gitignore - Git ignore file
┣ 📜.secret.toml -Secret configuration.
┣ 📜pyproject.toml - Project configuration file
...
We recommend keeping the configuration for pygen in the pyproject.toml file. This way, the configuration is
versioned together with the generated SDK. Making it easy for any team member to regenerate the SDK.
```toml ...
[tool.pygen]
data_models = [
["IntegrationTestsImmutable", "Movie", "2"],
]
tenant_id = "
...
[dependency-groups] dev = [ "cognite-pygen[all]", ```
Generating the SDK and Checking it into Version History
The instructions below assume you use git for version control.
Prerequisites: Instantiated a git repository and added the pyproject.toml, .gitignore and .secret.toml
in the root of the repository. (Create the files and run git init && git add . && git commit -m "initial commit")
Generating the SDK
- Check out a new branch for the SDK generation. (e.g.
git checkout -b sdk-generation) - Ensure that
pygenis installed and configured. (See Installation) - Run
pygen generateto generate the SDK. (e.g.pygen).pygenwill pick ut the configuration from thepyproject.tomland.secret.tomlfiles. - Commit the generated SDK to version history. (e.g.
git add . && git commit -m "generated sdk") - Push the branch to the remote repository. (e.g.
git push origin sdk-generation) - Create a pull request for the branch.
- Merge the pull request.