P4Python: Python interface to the Perforce API

Contents

  1. Introduction
  2. License
  3. Support
  4. Documentation
  5. Building P4Python
  6. Downloads
  7. Sample Code
  8. Porting
  9. Credits
  10. Changelog

Introduction

So, what's it all about? The observant amongst may notice a distinct resemblance to P4Ruby - which is intentional (thanks Tony)! P4Python allows you to write Python code that interacts nicely and intuitively with a Perforce server. The main features are:

Licence

This extension is distributed under the terms of this license. You use it at your own risk.

Support

P4Python is supported by me personally. You can contact me directly at: robert at vaccaperna dot co dot uk. 

Documentation

If you're new to Python, then start with www.python.org 

There is also documentation for P4Python.

Building P4Python

1. Download and install Python

Linux users can probably skip this step as most Linux distributions these days come with Python installed (or on the CD's)

Windows users can download a Windows installer for Python from ActiveState. This is currently known to work with 2.3.

Otherwise you can download the source for Python from www.python.org which is the main Python home page.

2. Download P4Python

Choose the build of P4Python you want to run. For now there is just a current release (in the future there may be "stable" releases).

Pick the appropriate file from the downloads section.

If you chose to use the Windows installer then the process ends with running the executable. You're then ready to start using P4Python. What follows is only applicable to those building P4Python from source.

3. Get the Perforce API

This step is only required if you're building P4Python from source.

See the Porting section below to help you find the right Perforce API build for your platform.

Then go to the Perforce download site and grab the p4api.tar file for your platform. Try to get the latest available release, but certainly no older than 2001.1.

Extract the files in the p4api.tar tarfile (WinZip can handle it for Windows users) into a sub directory called p4api of where the source files are (or edit setup.py below).

4. Build and install P4Python

P4Python uses Distutils (Python 2.2 and later).

  python setup.py install
should do the trick (requires C++ compiler to be installed).

Note that there is a supplied test harness (though it requires a working Perforce server with a copy of the training repository to run since it relies on certain history). It is valid example for how to use functions.

 

Downloads

Current Builds

Release Type Current Notes
Source Code p4python.zip Unzip and run "python setup.py install" to build and install

Windows Installers

Release Platform Python Version Installer - just download and run
0.6 Windows 2.3 P4Python-0.6.win32-py2.3.exe
0.6 Windows 2.4 P4Python-0.6.win32-py2.4.exe
0.6 Linux 2.4 P4Python-0.6.linux-i386.tar.gz

Older Releases

Windows Installers

Release Platform Python Version Installer - just download and run
0.5 Windows 2.3 P4Python-0.5.win32-py2.3.exe
0.5 Windows 2.4 P4Python-0.5.win32-py2.4.exe

Other platforms (binaries kindly sent in):
 
Release Platform Python Version Built Binary (unpack and copy to appropriate place) Thanks To
0.5 Cygwin 2.4 P4Python-0.5.cygwin-1.5.12-i686.tar.gz Adam Heinz
0.5 Linux 2.4 P4Python-0.5.linux-i686.tar.gz Tony Smith

 

To install from .tar.gz, unzip the 2 files (p4.py and P4Client.so). Find out where your Python libraries are located (by running "python -v" usually, or the following command:

python -c "import sys, string; print string.join(sys.path, '\n')"

and copy the 2 files into:

<python root>/lib/site-packages

To find out what's changed, read the change log.

Sample code

Please see P4Python documentation, particularly the Examples. Note that all functions are documented in the test harness (see comments for details).

Porting

P4Python is as portable as Python and Perforce so porting it is relatively easy. Most of the porting problems revolve around people not knowing which build of the Perforce API to use. The key is to match up the compiler used to build Python with the compiler used to build Perforce and Python and use that compiler to build P4Python.

P4Python has been built on at least the following platforms:

Note that P4Python is compatible with older versions of Python and the Perforce API, so on older platforms you should still be able to get a working build.

If you get "unresolved symbol" errors when building or running P4Python, you probably used the wrong compiler or the wrong Perforce API build.

Credits

Thanks to Mike Meyer for the original code.

Thanks to Tony Smith for producing P4Ruby after which this is modelled.

Changelog

See CHANGELOG.txt

File: $Id: //guest/robert_cowham/perforce/API/python/index.html#10 $