P4Python is the official Python API for Perforce Helix Core, allowing Python applications to interact with Perforce servers. It enables scripting of Perforce operations like file management, changelists, jobs, and user administration. The library is actively maintained with frequent releases, currently at version 2025.2.2863679.
pip install p4pythonVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to establish a connection to a Perforce Helix Core server, run a basic 'info' command, and properly disconnect. It prioritizes using environment variables for credentials where possible, falling back to placeholders.
Always call `p4.disconnect()` in a `finally` block to ensure the connection is closed, even if errors occur. The `P4` object is not a context manager.
Explicitly set `p4.charset = 'utf8'` (or the appropriate charset for your server) immediately after creating the `P4` object and before connecting. Ensure your Python script itself is saved with UTF-8 encoding.
Explicitly set `p4.port`, `p4.user`, `p4.client`, and `p4.password` attributes directly on the `P4` object in your code. Use `os.environ.get()` to retrieve default values if you still want environment variable fallback.
Before `p4.connect()`, ensure you set `p4.port = 'your_server:your_port'` (e.g., `p4.port = 'perforce:1666'`) or set the `P4PORT` environment variable.
Ensure `p4.connect()` is called and succeeds before attempting to run any Perforce commands like `p4.run('info')`.Verify that `p4.client` is set to an existing, valid client workspace name. You may need to create a new client workspace using `p4 client` on the command line or `p4.run('client', '-i', client_spec)` in your script.Set `p4.charset = 'utf8'` (or the appropriate charset like 'shiftjis', 'iso8859-1') after initializing `P4()` and before `p4.connect()`. Ensure your script's source file is also saved with the correct encoding (e.g., UTF-8).
No dependency data recorded yet.