I'm confused as why OpenTelemetry documentaion has OpenTelemetry Python API and OpenTelemetry Python SDK.
Like when using the specification in python when we should consider pip install opentelemetry-api
over pip install opentelemetry-sdk
There's no need to specify both the API and SDK dependencies in Python as the SDK has a dependency on the API:
The short answer for when to use each is that the API should be specified as a dependency for packages/libraries and the SDK for applications.
The reason for this is that API contains the interface for instrumenting code with traces, metrics and logs. The SDK contains the additional functionality to collect, process and export that data.
For example, if I wanted to include instrumentation in a PyPI package that I've created, I would add the API as a dependency and use that to instrument my code. Then if someone were to use my PyPI package in their application, they could include the instrumentation data that my package generates. However, they would have to install the SDK in order to configure their application to do anything with that telemetry data other than simply generate it, e.g. sending it to an OpenTelemetry collector or third party.