While fetching User Library albums at this endopoint:
https://api.spotify.com/v1/me/albums
See api reference here
the api call returns a small part of album list. But in Spotify App or Spotify Desktop App, it shows a different number of albums.
Does anyone know how to get artists from the library as I can't find any API documentation for it?
As per the documentation in Spotify's User Library endpoint:
The above call will only return user 's saved albums.
So if you want to retrieve all albums depicted in your desktop via api calls, you must save all of them within the Desktop app, otherwise you'll have the discrepancy you describe in your question.