https://github.com/cognitedata/pygen
The Cognite Python Data Modeling SDK Generator
https://github.com/cognitedata/pygen
data-modeling sdk-python
Last synced: 10 months ago
JSON representation
The Cognite Python Data Modeling SDK Generator
- Host: GitHub
- URL: https://github.com/cognitedata/pygen
- Owner: cognitedata
- License: apache-2.0
- Created: 2023-05-12T14:16:18.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-13T09:05:56.000Z (11 months ago)
- Last Synced: 2025-04-13T09:22:51.946Z (11 months ago)
- Topics: data-modeling, sdk-python
- Language: Python
- Homepage: https://cognite-pygen.readthedocs-hosted.com/en/latest/
- Size: 20 MB
- Stars: 5
- Watchers: 34
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
Cognite Python SDK Generator
==========================
[](https://github.com/cognitedata/pygen/actions/workflows/release.yaml)
[](https://cognite-pygen.readthedocs-hosted.com/en/latest/?badge=latest)
[](https://github.com/cognitedata/pygen)
[](https://pypi.org/project/cognite-pygen/)
[](https://pypistats.org/packages/cognite-pygen)
[](https://github.com/cognitedata/pygen/blob/master/LICENSE)
[](https://github.com/ambv/black)
[](https://github.com/astral-sh/ruff)
[](http://mypy-lang.org)
This is the Cognite Python SDK Generator, `pygen`. The purpose of this package is to help developers to
work with Cognite Data Fusion's (CDF) Data Models (DM) in Python.
The core functionality is to provide a Python client that matches a data model. This enables the developer for the following
benefits
* Client-side validation of the data before writing it to CDF.
* Autocompletion is matching the data model in the integrated developer environment (IDE). This is important as it enables:
* Discoverability of a data model through Python.
* Reduced typing errors in development.
* Keeping the language domain specific for the developer. Instead of working with generic concepts such as instances,
nodes and edges, the developer can work with the concepts in the data model.
## Documentation
See the [documentation](https://cognite-pygen.readthedocs-hosted.com/en/latest/) for more information.
## Installation
### Without any optional dependencies
To install this package without CLI support:
```bash
pip install cognite-pygen
```
### With optional dependencies
* `cli` This includes CLI support such that you can run the package from the command line.
```bash
pip install cognite-pygen[cli]
```
If using zsh:
```bash
pip install 'cognite-pygen[cli]'
```
## Usage
The goal of the package is to have representations of all the types in a given data model with API calls to *.list()*,
*.apply()*, *.delete()*, and *.retrieve()* individuals for each type.


## Creating a Python SDK from a Data Model
Given a Data Model with external id `Movie` in the space `movies` in CDF, the following command will generate a Python SDK
```bash
pygen generate --space movies \
--external-id Movie \
--version 1 \
--tenant-id \
--client-id \
--client-secret \
--cdf-cluster \
--cdf-project
```
If you are not using Microsoft Entra ID (Azure AD) you need to specify the parameter --token-url, --scopes and --audience instead of --tenant-id.
## Dependencies
### Dependencies for the generated SDK
* [cognite-sdk](https://cognite-sdk-python.readthedocs-hosted.com/en/latest/) This is the basis for all requests to the Cognite Data Fusion API.
* [pydantic](https://docs.pydantic.dev/latest/) This is used for all data classes in the generated SDK.
* [pandas](https://pandas.pydata.org/docs/) This is used for `.to_pandas()` methods in the generated SDK.
### Dependencies for the `pygen`
* [jinja2](https://jinja.palletsprojects.com/en/3.1.x/) This is used for the templating of the generated SDK.
* [inflect](https://pypi.org/project/inflect/) This is used for the singularization/pluralization of words in the generated SDK.
* [typer](https://typer.tiangolo.com/) (Optional) This is used for the CLI of the `pygen` package.
* [black](https://pypi.org/project/black/) (Optional) This is used to format the code generated by the `pygen` package.
## Changelog
Wondering about previous changes to the SDK? Take a look at the [CHANGELOG](https://github.com/cognitedata/pygen/blob/master/docs/CHANGELOG.md).
## Contributing
Want to contribute? Check out [CONTRIBUTING](https://github.com/cognitedata/pygen/blob/master/CONTRIBUTING.md).