Skip to main content

pypcd4

Test PyPI - Version PyPI - Python Version GitHub License PyPI - Downloads

Table of Contents

Description

pypcd4 is a modern reimagining of the original pypcd library, offering enhanced capabilities and performance for working with Point Cloud Data (PCD) files.

This library builds upon the foundation laid by the original pypcd while incorporating modern Python3 syntax and methodologies to provide a more efficient and user-friendly experience.

Installation

To get started with pypcd4, install it using pip:

pip install pypcd4

Usage

Let’s walk through some examples of how you can use pypcd4:

Getting Started

First, import the PointCloud class from pypcd4:

from pypcd4 import PointCloud

Working with .pcd Files

If you have a .pcd file, you can read it into a PointCloud object:

pc: PointCloud = PointCloud.from_path("point_cloud.pcd")

pc.fields
# ('x', 'y', 'z', 'intensity')

Converting Between PointCloud and NumPy Array

You can convert a PointCloud to a NumPy array:

array: np.ndarray = pc.numpy()

array.shape
# (1000, 4)

You can also specify the fields you want to include in the conversion:

array: np.ndarray = pc.numpy(("x", "y", "z"))

array.shape
# (1000, 3)

And you can convert a NumPy array back to a PointCloud. The method you use depends on the fields in your array:

# If the array has x, y, z, and intensity fields,
pc = PointCloud.from_xyzi_points(array)

# Or if the array has x, y, z, and label fields,
pc = PointCloud.from_xyzl_points(array, label_type=np.uint32)

Creating Custom Conversion Methods

If you can’t find your preferred point type in the pre-defined conversion methods, you can create your own:

fields = ("x", "y", "z", "intensity", "new_field")
types = (np.float32, np.float32, np.float32, np.float32, np.float64)

pc = PointCloud.from_points(array, fields, types)

Working with ROS PointCloud2 Messages

You can convert a ROS PointCloud2 Message to a PointCloud and vice versa. This requires ROS installed and sourced, or rosbags to be installed. To publish the converted message, ROS is required:

def callback(in_msg: sensor_msgs.msg.PointCloud2):
    # Convert ROS PointCloud2 Message to a PointCloud
    pc = PointCloud.from_msg(in_msg)

    pc.fields
    # ("x", "y", "z", "intensity", "ring", "time")

    # Convert PointCloud to ROS PointCloud2 Message with the input message header
    out_msg = pc.to_msg(in_msg.header)

    # Publish using ROS (or e.g. write to a rosbag)
    publisher.publish(out_msg)

Concatenating PointClouds

The pypcd4 supports concatenating PointCloud objects together using the + operator. This can be useful when you want to merge two point clouds into one.

Here's how you can use it:

pc1: PointCloud = PointCloud.from_path("xyzi1.pcd")
pc2: PointCloud = PointCloud.from_path("xyzi2.pcd")

# Concatenate two PointClouds
pc3: PointCloud = pc1 + pc2

Concatenating many PointClouds in sequence can become slow, especially for large point counts. Using PointCloud.from_list() will be faster for those use cases:

pc_list = []
for i in range(10):
    pc_list.append(PointCloud.from_path(f"xyzi{i}.pcd"))

pc: PointCloud = PointCloud.from_list(pc_list)

Please note that to concatenate PointCloud objects, they must have the exact same fields and types. If they don’t, a ValueError will be raised.

Filtering a PointCloud

The pypcd4 library provides a convenient way to filter a PointCloud using a subscript.

Using a Slice

You can use a slice to access a range of points in the point cloud. Here’s an example:

# Create a point cloud with random points
pc = PointCloud.from_xyz_points(np.random.rand(10, 3))

# Access points using a slice
subset = pc[3:8]

In this case, subset will be a new PointCloud object containing only the points from index 3 to 7.

Using a Boolean Mask

You can use a boolean mask to access points that satisfy certain conditions. Here’s an example:

# Create a point cloud with random points
pc = PointCloud.from_xyz_points(np.random.rand(10000, 3))

# Create a boolean mask
mask = (pc.pc_data["x"] > 0.5) & (pc.pc_data["y"] < 0.5)

# Access points using the mask
subset = pc[mask]

In this case, subset will be a new PointCloud object containing only the points where the x-coordinate is greater than 0.5 and the y-coordinate is less than 0.5.

Using Field Names

You can use a field name or a sequence of field names to access specific fields in the point cloud. Here’s an example:

# Create a point cloud with random points
pc = PointCloud.from_xyz_points(np.random.rand(100, 3))

# Access specific fields
subset = pc[("x", "y")]

In this case, subset will be a new PointCloud object containing only the x and y coordinates of the points. The z-coordinate will not be included.

Saving Your Work

Finally, you can save your PointCloud as a .pcd file:

pc.save("nice_point_cloud.pcd")

Contributing

We are always looking for contributors. If you are interested in contributing, please run the lint and test before submitting a pull request:

Just run the following commands:

uv sync
uv run ruff check --fix src
uv run ruff format src
uv run mypy src
uv run tox

Using pip

Install the testing dependencies by the following command:

pip install mypy pytest ruff

Then run the following command:

ruff check --fix src
ruff format src
mypy src
pytest

Make sure all lints and tests pass before submitting a pull request.

License

The library was rewritten and does not borrow any code from the original pypcd library. Since it was heavily inspired by the original author's work, we extend his original BSD 3-Clause License and include his Copyright notice.

Metadata

Release files for pypcd4 1.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pypcd4 1.5.1
File Size Uploaded
pypcd4-1.5.1.tar.gz 158.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pypcd4 1.5.1
File Interpreter ABI Platform
pypcd4-1.5.1-py3-none-any.whl Python 3 none any Details

Total release size: 174.1 kB

Release files / pypcd4-1.5.1.tar.gz

Download URL pypcd4-1.5.1.tar.gz
Size 158.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5427584a1b749b2d243baa4006ca4c62b9a3880a127c838c9ac9e5c7e9486ee4
BLAKE2b-256 checksum
How to use checksums
d6a58a94076ca71c0fb07241f820d93e951cb76deac021d04209ffbd93870684
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release files / pypcd4-1.5.1-py3-none-any.whl

Download URL pypcd4-1.5.1-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0b785176db6214a3496d6dd3518fce1d7cc5ce072b67157c65ed60beb344d222
BLAKE2b-256 checksum
How to use checksums
9633ce3e94d24494e4887b9cba170f6e02d14543b838315691e84ac1ae7cf047
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.5.1 This release

2 release files

1.5.0

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.4.10

2 release files

0.4.9

2 release files

0.4.8

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page