# @libp2p/pubsub

> libp2p pubsub base class

Latest version **10.1.18** (published 2025-08-20) · Apache-2.0 OR MIT license · 0 weekly downloads

## Install

```sh
npm install @libp2p/pubsub
pnpm add @libp2p/pubsub
yarn add @libp2p/pubsub
bun add @libp2p/pubsub
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 10.1.18 |
| Published | 2025-08-20 |
| First published | 2022-01-04 |
| Weekly downloads | 0 |
| License | Apache-2.0 OR MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 14 |
| Unpacked size | 1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2579 |
| Maintainers | daviddias, alanshaw, achingbrain, vascosantos, npm-service-account-libp2p, jacobheun |
| Keywords | interface, libp2p |

## Links

- npm: https://www.npmjs.com/package/@libp2p/pubsub
- Repository: https://github.com/libp2p/js-libp2p
- Homepage: https://github.com/libp2p/js-libp2p/tree/main/packages/pubsub#readme
- Issues: https://github.com/libp2p/js-libp2p/issues
- npm.io page: https://npm.io/package/@libp2p/pubsub

## Dependencies (14)

- [it-pipe](https://npm.io/package/it-pipe.md) ^3.0.1
- [p-queue](https://npm.io/package/p-queue.md) ^8.1.0
- [main-event](https://npm.io/package/main-event.md) ^1.0.1
- [it-pushable](https://npm.io/package/it-pushable.md) ^3.2.3
- [uint8arrays](https://npm.io/package/uint8arrays.md) ^5.1.0
- [multiformats](https://npm.io/package/multiformats.md) ^13.3.6
- [@libp2p/utils](https://npm.io/package/@libp2p/utils.md) ^6.7.2
- [@libp2p/crypto](https://npm.io/package/@libp2p/crypto.md) ^5.1.8
- [uint8arraylist](https://npm.io/package/uint8arraylist.md) ^2.4.8
- [@libp2p/peer-id](https://npm.io/package/@libp2p/peer-id.md) ^5.1.9
- [@libp2p/interface](https://npm.io/package/@libp2p/interface.md) ^2.11.0
- [it-length-prefixed](https://npm.io/package/it-length-prefixed.md) ^10.0.1
- [@libp2p/peer-collections](https://npm.io/package/@libp2p/peer-collections.md) ^6.0.35
- [@libp2p/interface-internal](https://npm.io/package/@libp2p/interface-internal.md) ^2.3.19

## Recent versions

- 10.1.18 (latest) — 2025-08-20
- 10.1.18-87bc8d4fb (next) — 2025-09-22
- 10.1.18-da78fa851 — 2025-09-19
- 10.1.18-8484de8a2 — 2025-09-08
- 10.1.18-0f07e3df5 — 2025-09-05
- 10.1.18-a02cb0461 — 2025-09-04
- 10.1.18-f5932c294 — 2025-08-20
- 10.1.17-5ed83dd69 — 2025-08-19
- 10.1.17-aa770ab81 — 2025-08-17
- 10.1.17-7ce083dca — 2025-08-14
- 10.1.17-cf9aab5c8 — 2025-07-30
- 10.1.17-cb1c14e62 — 2025-07-24
- 10.1.17-4420fad68 — 2025-07-13
- 10.1.17-79473c99a — 2025-07-10
- 10.1.17-ce6b542a8 — 2025-07-09
- … 767 more at https://npm.io/package/@libp2p/pubsub/versions

## README

# @libp2p/pubsub

[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p)
[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=main\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amain)

> libp2p pubsub base class

# About

<!--

!IMPORTANT!

Everything in this README between "# About" and "# Install" is automatically
generated and will be overwritten the next time the doc generator is run.

To make changes to this section, please update the @packageDocumentation section
of src/index.js or src/index.ts

To experiment with formatting, please run "npm run docs" from the root of this
repo and examine the changes made.

-->

A set of components to be extended in order to create a pubsub implementation.

## Example

```TypeScript
import { PubSubBaseProtocol } from '@libp2p/pubsub'
import type { PubSubRPC, PublishResult, PubSubRPCMessage, PeerId, Message } from '@libp2p/interface'
import type { Uint8ArrayList } from 'uint8arraylist'

class MyPubsubImplementation extends PubSubBaseProtocol {
  decodeRpc (bytes: Uint8Array | Uint8ArrayList): PubSubRPC {
    throw new Error('Not implemented')
  }

  encodeRpc (rpc: PubSubRPC): Uint8Array {
    throw new Error('Not implemented')
  }

  encodeMessage (rpc: PubSubRPCMessage): Uint8Array {
    throw new Error('Not implemented')
  }

  async publishMessage (sender: PeerId, message: Message): Promise<PublishResult> {
    throw new Error('Not implemented')
  }
}
```

# Install

```console
$ npm i @libp2p/pubsub
```

## Browser `<script>` tag

Loading this module through a script tag will make its exports available as `Libp2pPubsub` in the global namespace.

```html
<script src="https://unpkg.com/@libp2p/pubsub/dist/index.min.js"></script>
```

# API Docs

- <https://libp2p.github.io/js-libp2p/modules/_libp2p_pubsub.html>

# License

Licensed under either of

- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/pubsub/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/pubsub/LICENSE-MIT) / <http://opensource.org/licenses/MIT>)

# Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

---
_Source: https://npm.io/package/@libp2p/pubsub · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
