Helix Core is now P4. Product user interfaces will be updated soon. Learn more >>

P4 API for Python Documentation | 2025.2

# Class P4.Map

## Description

The `P4.Map` class allows users to create and work with P4 Server mappings, without requiring a connection to a P4 Server.

## Instance Attributes

None.

## Class Methods

### P4.Map( [ list ] ) -> P4.Map

Constructs a new `P4.Map` object.

### P4.Map.join ( map1, map2 ) -> P4.Map

Join two `P4.Map` objects and create a third.

The new map is composed of the left-hand side of the first mapping, as joined to the right-hand side of the second mapping. For example:

    # Map depot syntax to client syntax
    client_map = P4.Map()
    client_map.insert( "//depot/main/...", "//client/..." )

    # Map client syntax to local syntax
    client_root = P4.Map()
    client_root.insert( "//client/...", "/home/bruno/workspace/..." )

    # Join the previous mappings to map depot syntax to local syntax
    local_map = P4.Map.join( client_map, client_root )
    local_path = local_map.translate( "//depot/main/www/index.html" )

    # local_path is now /home/bruno/workspace/www/index.html

## Instance Methods

### map.clear()

Empty a map.

### map.count() -> int

Return the number of entries in a map.

### map.is_empty() -> boolean

Test whether a map object is empty.

### map.insert( string …​ )

Inserts an entry into the map.

May be called with one or two arguments. If called with one argument, the string is assumed to be a string containing either a half-map, or a string containing both halves of the mapping. In this form, mappings with embedded spaces must be quoted. If called with two arguments, each argument is assumed to be half of the mapping, and quotes are optional.

    # called with two arguments:
    map.insert( "//depot/main/...", "//client/..." )

    # called with one argument containing both halves of the mapping:
    map.insert( "//depot/live/... //client/live/..." )

    # called with one argument containing a half-map:
    # This call produces the mapping "depot/... depot/..."
    map.insert( "depot/..." )

### map.translate ( string, [ boolean ] ) -> string

Translate a string through a map, and return the result. If the optional second argument is `1`, translate forward, and if it is `0`, translate in the reverse direction. By default, translation is in the forward direction.

### map.includes( string ) -> boolean

Tests whether a path is mapped or not.

    if map.includes( "//depot/main/..." ):
      ...

### map.reverse() -> P4.Map

Return a new `P4.Map` object with the left and right sides of the mapping swapped. The original object is unchanged.

### map.lhs() -> list

Returns the left side of a mapping as an array.

### map.rhs() -> list

Returns the right side of a mapping as an array.

### map.as_array() -> list

Returns the map as an array.

Your search for returned results