On this page
  1. posixpath
  2. Import
  3. Overview
  4. Quick Start
  5. Implementation Walkthrough
  6. 1. Normalizing Virtual or Remote POSIX Paths Cross-Platform
  7. Gotchas & Boundaries
  8. Common Functions
  9. Constants & Attributes

posixpath

Prev: posix | Up: stdlib_module | Next: pprint
Rel: pathlib, os, io, time, fileinput
Ref: docs.python.org — posixpath
Tags: #public #python3 #stdlib


Import

import posixpath

Overview

POSIX (slash-separated /a/b/c) path-manipulation implementation backing os.path on macOS, Linux, and BSD. For normal local filesystem work, use pathlib (Path) or os.path; import posixpath directly only when you explicitly need POSIX path semantics on any OS (such as normalizing URL paths, S3 keys, or container paths from Windows).

Quick Start

import posixpath

# Works identically on Windows, macOS, and Linux
joined = posixpath.join("/var/www", "assets", "logo.png")
assert joined == "/var/www/assets/logo.png"
assert posixpath.normpath("/a/b/../c/") == "/a/c"

Implementation Walkthrough

1. Normalizing Virtual or Remote POSIX Paths Cross-Platform

When manipulating paths inside zip archives, tarballs, Docker images, or object storage keys, posixpath (or pathlib.PurePosixPath) guarantees forward slashes regardless of host OS:

import posixpath

key = posixpath.join("releases", "2026", "v1.0.tar.gz")
directory, filename = posixpath.split(key)
assert directory == "releases/2026" and filename == "v1.0.tar.gz"

Gotchas & Boundaries

Common Functions

Constants & Attributes

Linked from

Related notes