Back to series
· 10 min read

Standard Library and Third-Party Libraries


I. What Is the Standard Library?

The standard library is a set of foundational functionality provided by a programming language or its official platform, typically shipped with the language implementation, development kit, or runtime environment.

It gives developers common, general-purpose capabilities, so that every project doesn't have to implement basic functionality from scratch.

For example:

  • File reading and writing
  • String processing
  • Mathematical computation
  • Date and time
  • Collections and data structures
  • Network communication
  • Concurrency and threads
  • Data serialization
  • Exception handling

The standard library is usually defined by the language standard, platform specification, or official implementation, but different languages have different conventions regarding its scope and how it is delivered.

1. Main Characteristics of the Standard Library

Officially maintained

The standard library is typically designed, maintained, and evolved by the language standards body, official team, or platform maintainers.

Rich foundational functionality

The standard library covers common development needs, such as file operations, string processing, collection operations, and network communication.

Relatively stable compatibility

The standard library generally values backward compatibility, but that does not mean every API stays unchanged forever. Some functionality may be deprecated, adjusted, or removed.

Usually provided with the development or runtime environment

Using the standard library generally does not require hunting for and installing it separately the way third-party libraries do, though this depends on the language, runtime environment, and deployment approach.

Platform adaptation

The standard library usually wraps operating system differences to provide programs with a relatively uniform interface. However, some functionality may still be limited by the operating system, runtime environment, and hardware capabilities.

2. Common Standard Library Functionality

Category Main Purpose Typical Capabilities
Input/Output Data reading and writing Console, files, streams
String processing Text manipulation Concatenation, search, formatting
Mathematical computation Numeric processing Trigonometric functions, random numbers
Collection types Data organization Lists, maps, sets
Date and time Time handling Date parsing, time zones
File system File management Create, delete, traverse
Network communication Network access Sockets, HTTP clients
Concurrent programming Parallel tasks Threads, locks, tasks
Serialization Data conversion JSON, binary encoding
Security and encryption Basic security operations Hashing, cryptography interfaces

Note that the fact that the standard library provides a certain capability does not mean it necessarily provides a complete, production-grade solution. For example, the standard library may provide a basic HTTP client, but not necessarily a full API gateway, service governance, or a complex retry system.

II. Standard Libraries in Different Languages

Standard libraries differ markedly across languages in their design goals, functional scope, and implementation approach.

1. The Python Standard Library

The Python standard library is feature-rich, covering areas such as file handling, networking, data structures, concurrency, testing, and system administration.

Common modules:

Module Main Functionality
os Operating system interface
sys Interpreter and runtime environment interface
pathlib Object-oriented path handling
json JSON encoding and decoding
datetime Date and time
math Mathematical operations
re Regular expressions
collections Extended collection types
itertools Iterator tools
threading Thread management
asyncio Asynchronous I/O
logging Log management
unittest Unit testing

Example:

import json
from pathlib import Path
from datetime import datetime

data = {
    "name": "Alice",
    "created_at": datetime.now().isoformat()
}

# Serialize JSON using the standard library
content = json.dumps(data, ensure_ascii=False, indent=2)

# Write to a file using pathlib
file_path = Path("data.json")
file_path.write_text(content, encoding="utf-8")

# Read the file
result = json.loads(file_path.read_text(encoding="utf-8"))

print(result)

The json, pathlib, and datetime modules used here all belong to the Python standard library and do not need to be installed separately via pip.

2. Java Standard Library

The Java standard library is mainly provided through the Java platform API, covering capabilities such as collections, input/output, networking, concurrency, date and time, and security.

Common packages:

Package Main functionality
java.lang Basic language classes
java.util Collections and utility classes
java.io Traditional input/output
java.nio Buffers and file system
java.time Date and time
java.net Network communication
java.util.concurrent Concurrency utilities
java.security Security-related APIs
java.sql Database access interfaces

Example:

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        List<String> names = new ArrayList<>();

        names.add("Alice");
        names.add("Bob");

        LocalDateTime now = LocalDateTime.now();

        System.out.println(names);
        System.out.println(now);
    }
}

List, ArrayList, and LocalDateTime all come from the standard APIs provided by the Java platform.

3. JavaScript Standard Built-in Capabilities

The JavaScript language specification defines ECMAScript built-in objects and standard language capabilities.

Common built-in objects include:

Object Main functionality
Array Array operations
Object Object operations
String String processing
Number Numeric processing
Map Key-value collections
Set Collections of unique values
Promise Asynchronous result management
Date Date and time
RegExp Regular expressions
JSON JSON encoding and decoding
Math Mathematical operations

Example:

const users = [
  { id: 1, name: "Alice" },
  { id: 2, name: "Bob" }
];

const names = users.map(user => user.name);

const userMap = new Map(
  users.map(user => [user.id, user])
);

console.log(names);
console.log(userMap.get(1));

Here, Array, Map, and similar features are built-in capabilities defined by the ECMAScript standard.

It is important to distinguish:

  • Array, Promise, and similar features are part of the ECMAScript language standard.
  • fetch, localStorage, the DOM, and similar features are usually provided by the host environment, and not all JavaScript environments have them.
  • Node.js's fs, path, and similar features are APIs provided by Node.js, not part of the ECMAScript standard library.

4. Go Standard Library

The Go standard library covers common areas such as networking, files, concurrency, encoding, cryptography, and testing.

Common packages:

Package Main functionality
fmt Formatted input and output
os Operating system interface
io Input/output abstraction
strings String processing
strconv Type conversion
time Time handling
net/http HTTP communication
encoding/json JSON encoding and decoding
sync Concurrency synchronization
context Context and cancellation control
testing Testing framework

Example:

package main

import (
    "encoding/json"
    "fmt"
    "time"
)

type User struct {
    Name string `json:"name"`
    Age  int    `json:"age"`
}

func main() {
    user := User{
        Name: "Alice",
        Age:  25,
    }

    data, err := json.Marshal(user)
    if err != nil {
        panic(err)
    }

    fmt.Println(string(data))
    fmt.Println(time.Now())
}

These packages are all part of the official Go standard library.

5. Rust Standard Library

The Rust standard library provides foundational functionality such as collections, strings, files, iterators, threads, and synchronization.

Common modules:

Module Main functionality
std::collections Collection types
std::fs File system
std::io Input/output
std::thread Threads
std::sync Synchronization primitives
std::time Time handling
std::path Path handling
std::process Process management
std::net Network communication

Example:

use std::collections::HashMap;
use std::fs;

fn main() {
    let mut users = HashMap::new();

    users.insert(1, "Alice");
    users.insert(2, "Bob");

    let content = format!("{:?}", users);

    fs::write("users.txt", content)
        .expect("failed to write file");

    println!("{:?}", users);
}

The Rust standard library provides foundational infrastructure, but many ecosystem features—such as asynchronous runtimes, complex HTTP clients, and database drivers—are usually provided by third-party crates.

3. What Is a Third-Party Library?

A third-party library is a software component developed and released by individuals, communities, enterprises, or organizations outside the language's official standard library.

They are used to extend language capabilities, solve problems in specific domains, or provide higher-level and more convenient abstractions than the standard library.

For example:

  • Python: NumPy, Pandas, Django, FastAPI.
  • Java: Spring Framework, Guava, MyBatis.
  • JavaScript: React, Vue, Axios, Lodash.
  • Go: Gin, GORM, Cobra.
  • Rust: Tokio, Serde, Axum.

Third-party libraries can be open-source projects or commercial software; they may be free to use, or they may require payment or compliance with a specific license agreement.

1. Main Characteristics of Third-Party Libraries

Feature expansion

Third-party libraries can provide capabilities in areas not covered by the standard library, such as machine learning, image processing, web development, and database access.

Community or enterprise maintenance

Maintainers may be individuals, open-source communities, foundations, or commercial companies. Project quality and maintenance cycles vary.

Independent releases and version management

Third-party libraries usually have their own version numbers, release cycles, and compatibility policies.

Dependency management required

Projects generally install, update, and lock third-party dependencies through package managers.

Quality and security require evaluation

Developers need to pay attention to the maintenance quality, vulnerability status, dependency relationships, and licenses of third-party libraries.

2. Common Types of Third-Party Libraries

Type Main use Representative projects
Web frameworks Web application development Django, Spring, Gin
Data processing Data analysis and computation NumPy, Pandas
Database access ORM and database drivers SQLAlchemy, GORM
HTTP clients Network requests Axios, Requests
Serialization Data encoding and decoding Serde, Jackson
Logging tools Logging and analysis Logback, Zap
Testing frameworks Automated testing pytest, JUnit
UI frameworks User interface construction React, Vue
Asynchronous frameworks Asynchronous tasks and network services Tokio, Netty

4. Core Differences Between Standard Libraries and Third-Party Libraries

Both standard libraries and third-party libraries are important forms of software reuse, but they differ in terms of origin, maintenance, compatibility, and usage costs.

1. Side-by-Side Comparison

Comparison dimension Standard library Third-party library
Origin Official language or platform ecosystem Community, enterprise, or individual
Maintainer Official teams, standards organizations, or platform maintainers Project maintainers
Functional scope Mainly general-purpose foundational capabilities Can cover any specialized domain
Installation method Usually provided with the language environment Usually installed through a package manager
Version management Usually evolves with language or platform versions Independently released versions
Compatibility Usually has a relatively clear platform compatibility policy Depends on the project's maintenance policy
Maintenance responsibility Official or platform maintainers bear primary responsibility Users need to evaluate maintenance status
Feature richness Foundational and general-purpose Can be deeply extended for specific scenarios
Dependency cost Usually relatively low May introduce transitive dependencies
Security risk Platform vulnerabilities still need attention Requires attention to the library itself and its dependency chain

2. The Two Are Not in Competition with Each Other

Standard libraries and third-party libraries often work together.

For example, a web application might use:

  • The standard library handles dates, strings, and file paths.
  • A third-party web framework handles routing and requests.
  • A third-party ORM handles database mapping.
  • A third-party logging library handles structured logging.

Sound engineering design is not about completely rejecting third-party libraries, but about choosing the appropriate level of abstraction according to requirements.

5. Differences Between Packages, Modules, Libraries, and Frameworks

In real-world development, packages, modules, libraries, and frameworks often appear together, but they are not exactly the same concepts.

1. Module

A module is usually the basic unit for organizing code and can contain functions, classes, variables, and other code definitions.

For example:

  • In Python, a .py file can usually serve as a module.
  • In JavaScript, modules can be defined through import and export.
  • In Java, code is organized through packages and classes, and the module system can also declare modules through module-info.java.

2. Package

A package is usually used to organize and distribute related modules.

For example:

  • Python pip packages.
  • Java Maven artifacts.
  • JavaScript npm packages.
  • Go modules and packages.
  • Rust crates.

Different languages do not define terms such as package, module, and crate in exactly the same way, so you cannot simply assume they denote the same level in every language.

3. Library

A library is a collection of code that other programs can call and reuse.

It may consist of one or more modules or packages, and it usually provides a well-defined functional interface.

Examples include date-processing libraries, image-processing libraries, and database access libraries.

4. Framework

A framework usually provides a more complete application structure and control flow.

Compared with an ordinary library, a framework tends to prescribe how an application is organized and calls code written by the developer at specific points.

For example:

  • Django: a web application framework.
  • Spring: a Java application development framework.
  • React: a library for building user interfaces, usually combined with routing, build tools, and so on to form a frontend application system.
  • Gin: a Go web framework.

5. How the four relate

flowchart TD
    A["Software code organization and reuse"]
    A --> B["Module"]
    A --> C["Package"]
    A --> D["Library"]
    A --> E["Framework"]
    B --> F["Organize code"]
    C --> G["Organize and distribute modules"]
    D --> H["Provide reusable functionality"]
    E --> I["Provide application structure and control flow"]

    style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style B fill:#E5F4EC,stroke:#A3CBB5,color:#334155
    style C fill:#F3EDFC,stroke:#C4B2E3,color:#334155
    style D fill:#FFF5DE,stroke:#E8D29A,color:#334155
    style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
    style F fill:#E8EDF2,stroke:#B8C3CE,color:#334155
    style G fill:#E8EDF2,stroke:#B8C3CE,color:#334155
    style H fill:#E8EDF2,stroke:#B8C3CE,color:#334155
    style I fill:#E8EDF2,stroke:#B8C3CE,color:#334155
    linkStyle default stroke:#A3B8AC,stroke-width:1.5px

This diagram shows the commonly understood relationships between the concepts; it is not a strict containment hierarchy. Specific languages may organize modules, packages, and libraries in different ways.

VI. Installing Third-Party Libraries and Dependency Management

Third-party libraries usually need to be installed and managed through a package management tool.

A package manager is responsible not only for downloading packages but may also handle dependency resolution, version constraints, integrity verification, and lock file generation.

1. Python: pip

Python commonly uses pip to install third-party packages.

# Install Requests
python -m pip install requests

# Install a specific version
python -m pip install requests==2.32.3

# List installed packages
python -m pip list

# Show dependency information
python -m pip show requests

# Export environment dependencies
python -m pip freeze > requirements.txt

In projects, it is usually recommended to use a virtual environment to prevent dependencies of different projects from interfering with each other.

# Create a virtual environment
python -m venv .venv

# Activate the environment: Linux / macOS
source .venv/bin/activate

# Install dependencies
python -m pip install requests

2. Java: Maven and Gradle

Java commonly uses Maven or Gradle to manage third-party dependencies.

Maven example:

<dependencies>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>33.3.1-jre</version>
    </dependency>
</dependencies>

Gradle example:

dependencies {
    implementation("com.google.guava:guava:33.3.1-jre")
}

The build tool resolves the relevant components according to the dependency declarations and adds them to the project build path.

3. JavaScript: npm

JavaScript projects commonly use npm to manage dependencies.

# Initialize a project
npm init -y

# Install a third-party library
npm install axios

# Install a development dependency
npm install --save-dev typescript

# View dependencies
npm list

# Update dependencies within version constraints
npm update

package.json is used to declare project dependencies and related configuration, while package-lock.json is used to lock the specific dependency resolution results.

4. Go: Go Modules

Go uses Go Modules to manage project dependencies.

# Initialize the module
go mod init example.com/myapp

# Add dependencies
go get github.com/gin-gonic/gin

# Tidy dependencies
go mod tidy

# View the dependency graph
go mod graph

Go typically uses go.mod to declare the module and its dependency requirements, and go.sum to record checksums of the dependency contents.

5. Rust: Cargo

Rust uses Cargo to manage projects, dependencies, and the build process.

# Create a project
cargo new myapp

# Add dependencies
cargo add serde

# Build the project
cargo build

# Run tests
cargo test

# View the dependency tree
cargo tree

Cargo.toml is used to declare dependencies, and Cargo.lock is used to lock in the specific resolved versions.

VII. The Core Mechanisms of Dependency Management

Dependency management is not simply downloading a library; it also involves mechanisms such as version constraints, dependency resolution, transitive dependencies, and lock files.

1. Direct Dependencies and Transitive Dependencies

A direct dependency is a library that a project explicitly declares and uses.

A transitive dependency is another library that a direct dependency itself depends on.

For example: