Evaluate an Unfamiliar Library before Adopting It
Core idea
Start from the versioned standard-library index and choose a module whose purpose matches the problem. Read availability, input and return types, exceptions, version changes and resource requirements. Verify with a bounded fixture, record assumptions, and select a third-party package only if the standard API does not satisfy the contract. For example, statistics.median calculates the middle value of ordered data, averaging the two central values for an even count.
from statistics import medianprint(median([9, 1, 5]))print(median([1, 3, 7, 9]))Input need not already be sorted; the even-sized result averages 3 and 7.
Expected output:
55.0Turn a documented exception into evidence
from statistics import median, StatisticsErrortry: median([])except StatisticsError: print('empty input rejected')The empty-input contract is observable; callers can decide whether to reject or handle missing data explicitly.
Expected output:
empty input rejectedCommon mistake
Do not use the function name as the entire specification. Read edge cases such as NaN handling, empty input and unsupported mixed types. A module import does not establish that a particular API is correct for your project.
Practice
Pick an unfamiliar standard-library function. Record its versioned URL, parameters, result, one edge case, one exception and one small verified example. Explain whether an external dependency is justified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Specialized library discovery
Check your understanding of specialized library discovery.
What is printed?
from statistics import medianprint(median([2,8]))What is printed?
from statistics import median, StatisticsErrortry: median([])except StatisticsError: print("empty")What should you inspect before adopting an API?
When is an external dependency justified?