It's not hard and fast but:
- API is the actual interface for the functions, not the implementation. It's possible for one API to be implemented by more than one library.
- Library is a bunch of code provided together. It might have more specific meaning depending on the language.
- A package is something you can install. It's pretty much synonymous to library since most packages contain one library.
- A framework is just a library that dictates a lot about how your app works.
Apart from API they don't really have strict definitions so they'll be used interchangeably and differently depending on the language.