Metadata-Version: 2.4
Name: prsm-network
Version: 1.7.0
Summary: Protocol for Recursive Scientific Modeling - A P2P infrastructure protocol for open-source collaboration
Author-email: PRSM Team <team@prsm.org>
Maintainer-email: PRSM Team <team@prsm.org>
License: MIT
Project-URL: Homepage, https://github.com/Ryno2390/PRSM
Project-URL: Documentation, https://prsm.readthedocs.io
Project-URL: Repository, https://github.com/Ryno2390/PRSM.git
Project-URL: Issues, https://github.com/Ryno2390/PRSM/issues
Project-URL: Changelog, https://github.com/Ryno2390/PRSM/blob/main/CHANGELOG.md
Keywords: scientific-modeling,ai,decentralized,p2p,research,federation,machine-learning
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Web Environment
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fastapi>=0.104.0
Requires-Dist: uvicorn[standard]>=0.24.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: pydantic-settings>=2.0.0
Requires-Dist: email-validator>=2.0.0
Requires-Dist: sqlalchemy>=2.0.0
Requires-Dist: asyncpg>=0.29.0
Requires-Dist: redis>=5.0.0
Requires-Dist: aiohttp>=3.9.0
Requires-Dist: aiosqlite>=0.19.0
Requires-Dist: structlog>=23.0.0
Requires-Dist: rich>=13.7.0
Requires-Dist: click>=8.1.0
Requires-Dist: simple-term-menu>=1.6.0
Requires-Dist: python-dotenv>=1.0.0
Requires-Dist: httpx>=0.25.0
Requires-Dist: websockets>=12.0
Requires-Dist: cryptography>=41.0.0
Requires-Dist: pyjwt>=2.8.0
Requires-Dist: bcrypt>=4.1.0
Requires-Dist: passlib>=1.7.4
Requires-Dist: pynacl>=1.5.0
Requires-Dist: prometheus-client>=0.19.0
Requires-Dist: psutil>=5.9.0
Requires-Dist: streamlit>=1.28.0
Requires-Dist: numpy>=1.24.0
Requires-Dist: aiofiles>=23.0.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
Requires-Dist: pytest-mock>=3.12.0; extra == "dev"
Requires-Dist: pytest-xdist>=3.5.0; extra == "dev"
Requires-Dist: coverage[toml]>=7.0.0; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"
Requires-Dist: isort>=5.12.0; extra == "dev"
Requires-Dist: flake8>=6.1.0; extra == "dev"
Requires-Dist: mypy>=1.7.0; extra == "dev"
Requires-Dist: ruff>=0.1.0; extra == "dev"
Requires-Dist: bandit>=1.7.0; extra == "dev"
Requires-Dist: safety>=2.3.0; extra == "dev"
Requires-Dist: sphinx>=7.0.0; extra == "dev"
Requires-Dist: sphinx-rtd-theme>=2.0.0; extra == "dev"
Requires-Dist: myst-parser>=2.0.0; extra == "dev"
Requires-Dist: build>=1.0.0; extra == "dev"
Requires-Dist: twine>=4.0.0; extra == "dev"
Requires-Dist: setuptools-scm>=8.0.0; extra == "dev"
Provides-Extra: ml
Requires-Dist: torch>=2.0.0; extra == "ml"
Requires-Dist: transformers>=4.35.0; extra == "ml"
Requires-Dist: sentence-transformers>=2.2.0; extra == "ml"
Requires-Dist: chromadb>=0.4.0; extra == "ml"
Provides-Extra: blockchain
Requires-Dist: web3>=6.0.0; extra == "blockchain"
Requires-Dist: eth-account>=0.9.0; extra == "blockchain"
Requires-Dist: hexbytes>=0.3.0; extra == "blockchain"
Provides-Extra: vectorstore
Requires-Dist: pymilvus>=2.3.0; extra == "vectorstore"
Requires-Dist: qdrant-client>=1.7.0; extra == "vectorstore"
Requires-Dist: pinecone-client>=3.0.0; extra == "vectorstore"
Provides-Extra: wasm
Requires-Dist: wasmtime>=22.0.0; extra == "wasm"
Provides-Extra: gpu
Requires-Dist: nvidia-ml-py3>=12.0.0; extra == "gpu"
Requires-Dist: GPUtil>=1.4.0; extra == "gpu"
Provides-Extra: distillation
Requires-Dist: bitsandbytes>=0.41.0; extra == "distillation"
Requires-Dist: accelerate>=0.24.0; extra == "distillation"
Provides-Extra: bittorrent
Requires-Dist: libtorrent>=2.0.9; extra == "bittorrent"
Requires-Dist: bencodepy>=4.0.0; extra == "bittorrent"
Provides-Extra: server
Requires-Dist: bleach>=6.0.0; extra == "server"
Requires-Dist: psutil>=5.9.0; extra == "server"
Requires-Dist: jinja2>=3.1.0; extra == "server"
Requires-Dist: greenlet>=3.0.0; extra == "server"
Requires-Dist: python-multipart>=0.0.6; extra == "server"
Requires-Dist: pandas>=2.0.0; extra == "server"
Provides-Extra: mcp
Requires-Dist: fastmcp>=2.0.0; extra == "mcp"
Provides-Extra: all
Requires-Dist: prsm[bittorrent,blockchain,dev,distillation,gpu,mcp,ml,server,vectorstore]; extra == "all"
Dynamic: license-file

# PRSM: P2P Infrastructure Protocol for Open-Source Collaboration

**The code goes to the data. Not the other way around.**

PRSM is a P2P infrastructure protocol that aggregates latent storage, compute, and data from consumer nodes — gaming PCs, consoles, laptops, phones — into a mesh network accessible to third-party LLMs via MCP tools. Contributors earn FTNS tokens for sharing their latent resources; users leverage PRSM infrastructure through their preferred LLMs (local or via OAuth/API). PRSM is not an AGI framework. Reasoning happens in third-party LLMs; PRSM provides the infrastructure those LLMs use to access distributed resources and data.

**Version 1.7.0** | [PyPI](https://pypi.org/project/prsm-network/) | [Getting Started](docs/GETTING_STARTED.md) | [Architecture Spec](docs/SOVEREIGN_EDGE_AI_SPEC.md)

[![PyPI version](https://badge.fury.io/py/prsm-network.svg)](https://pypi.org/project/prsm-network/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![MCP Tools](https://img.shields.io/badge/MCP%20tools-16-blue.svg)](#mcp-integration)

---

## Why PRSM Exists

**The problem:** Frontier AI labs hoard data, compute, and models behind API walls. Every query you send to a centralized API is logged, stored, and potentially trained on. Meanwhile, billions of consumer devices sit idle — gaming PCs, laptops, phones, tablets — each with storage, compute, and sometimes proprietary data that never leave the device.

**The PRSM thesis:** Build an open-source commons for AI infrastructure. Aggregate the latent resources of consumer electronics into a P2P mesh. Let any LLM — local, OAuth, or API — use that mesh via MCP tools. Pay contributors in FTNS tokens so sharing beats hoarding.

| Centralized AI (today) | PRSM |
|------------------------|------|
| You upload data to their cloud | WASM agents travel to the data |
| They see your query | Zero-persistence sandbox — nothing logged |
| One datacenter processes everything | Thousands of edge nodes work in parallel |
| You pay per token | Hybrid pricing — commodity compute + market-rate data |
| Vendor lock-in | Works with any LLM via MCP |

**The result:** A network where the model is open but the computation is private, and where contributing your idle storage/compute/data earns you a share of every query it serves.

---

## Quick Start

```bash
# Install
pip install prsm-network

# Check your hardware
prsm node benchmark

# Start your node
prsm node start

# Expose PRSM tools to any MCP-compatible LLM
prsm mcp-server
```

> **FTNS tokens:** Providers earn FTNS for sharing storage, compute, and data through their node. New nodes receive a 100 FTNS welcome grant. Third-party LLMs invoke PRSM tools via MCP; reasoning happens in the LLM, execution happens on PRSM nodes.

See the full [Getting Started Guide](docs/GETTING_STARTED.md) for detailed setup.

---

## How It Works

### The 10-Ring Architecture

PRSM is built as concentric capability rings. Each ring wraps and enriches the ones inside it.

| Ring | Name | What It Does |
|------|------|-------------|
| 1 | **The Sandbox** | WASM runtime with Wasmtime — sandboxed execution with memory/time limits |
| 2 | **The Courier** | Mobile agent dispatch — agents travel to data via P2P gossip + bidding |
| 3 | **The Swarm** | Semantic sharding — data split by meaning, parallel map-reduce across nodes |
| 4 | **The Economy** | Hybrid pricing — deterministic compute rates + market-rate data + 80/15/5 revenue splits |
| 5 | **Agent Forge** | WASM mobile agent runtime — query decomposition is performed by the caller's third-party LLM; PRSM dispatches the resulting WASM agents |
| 6 | **The Polish** | Production hardening — dynamic gas, RPC failover, CLI commands |
| 7 | **The Vault** | Confidential compute — TEE abstraction + differential privacy noise |
| 8 | **The Shield** | Model sharding — tensor parallelism + randomized pipelines + collision detection |
| 9 | **The Mind** | NWTN training pipeline — collect traces, evaluate quality, deploy fine-tuned models (reserved for future work) |
| 10 | **The Fortress** | Security — integrity verification, privacy budgets, hash-chained audit logs |

### End-to-End Flow

```
Third-party LLM (Claude/GPT/local): calls prsm_analyze via MCP

  → LLM:     Decomposes the query into WASM agent instructions
  → Ring 3:  Finds relevant semantic shards by embedding similarity
  → Ring 4:  Quotes cost: compute + data + network fee
  → Ring 3:  Fans out parallel agents to shard-holding nodes
  → Ring 2:  Each agent dispatched via gossip bidding
  → Ring 1:  Executed in WASM sandbox on provider hardware
  → Ring 7:  Differential privacy noise applied
  → Ring 3:  Results aggregated when quorum met
  → Ring 4:  FTNS settled: 80% data owner / 15% compute / 5% treasury

  ← Result returned to the LLM for final synthesis
```

---

## MCP Integration

Any LLM can use PRSM as a compute backend via the Model Context Protocol. **16 tools** are exposed:

```bash
prsm mcp-server    # Start the MCP server
```

Configure in Claude Desktop (`~/.claude/claude_desktop_config.json`):
```json
{"mcpServers": {"prsm": {"command": "python", "args": ["scripts/prsm_mcp_server.py"]}}}
```

Then Claude (or any MCP-compatible LLM) can:

| Tool | What It Does |
|------|-------------|
| `prsm_analyze` | Full Ring 1-10 pipeline — query in, answer out |
| `prsm_quote` | Cost estimate before committing (free) |
| `prsm_create_agent` | Build custom agent with 11 data operations |
| `prsm_dispatch_agent` | Execute agent on the network |
| `prsm_upload_dataset` | Publish data with pricing |
| `prsm_list_datasets` | Browse available datasets |
| `prsm_search_shards` | Find relevant data shards |
| `prsm_yield_estimate` | "What would I earn?" |
| `prsm_stake` | Staking tier info |
| `prsm_revenue_split` | Calculate 80/15/5 distribution |
| `prsm_hardware_benchmark` | GPU, TFLOPS, tier, TEE detection |
| `prsm_node_status` | Ring 1-10 health check |
| `prsm_agent_status` | Check running agent |
| `prsm_settlement_stats` | FTNS settlement queue |
| `prsm_privacy_status` | Differential privacy budget |
| `prsm_training_status` | NWTN training corpus quality |

---

## For Data Providers

Publish data through your node's ContentStore and earn 80% of every query against it:

```bash
prsm storage upload ./my_dataset.parquet \
  --description "NADA NC Vehicle Registrations 2025" \
  --royalty-rate 0.05 \
  --replicas 5
```

Revenue split: **80% to you**, 15% to compute providers, 5% to PRSM treasury.

---

## For Compute Providers

Check what you'd earn and start providing:

```bash
prsm node benchmark                           # See your hardware tier
prsm ftns yield-estimate --hours 8 --stake 1000   # Monthly earnings estimate
prsm node start                                # Start earning
```

**Staking tiers:**

| Tier | Stake | Yield Boost |
|------|-------|-------------|
| Casual | 0 FTNS | 1.0x |
| Pledged | 100 FTNS | 1.25x |
| Dedicated | 1,000 FTNS | 1.5x |
| Sentinel | 10,000 FTNS | 2.0x + aggregator fees |

---

## Privacy Architecture

PRSM provides three layers of privacy by construction — not by policy:

1. **WASM Zero-Persistence** — The sandbox has no filesystem, no network, no state after execution. The agent literally *cannot* persist data.
2. **Semantic Data Sharding** — No single node holds the full dataset. Each node sees only its assigned shard.
3. **Differential Privacy** — Calibrated Gaussian noise on all intermediate activations (configurable ε: 8.0 standard, 4.0 high, 1.0 maximum).

For proprietary models, **tensor-parallel model sharding** distributes weights across nodes so no single operator can reconstruct the model. **Randomized pipeline assignment** changes the topology per inference. **Collision detection** catches tampering.

See [Confidential Compute Spec](docs/CONFIDENTIAL_COMPUTE_SPEC.md) for details.

---

## SDKs

| Language | Install | Docs |
|----------|---------|------|
| **Python** | `pip install prsm-network` | [SDK Guide](docs/SDK_DEVELOPER_GUIDE.md) |
| **JavaScript** | `npm install prsm-sdk` | [sdks/javascript/](sdks/javascript/) |
| **Go** | `go get github.com/Ryno2390/PRSM/sdks/go@v0.37.0` | [sdks/go/](sdks/go/) |

```python
from prsm.sdk import PRSMClient

client = PRSMClient("http://localhost:8000")
result = await client.query("EV trends in NC", budget=10.0, privacy="standard")
quote = await client.quote("EV trends", shards=5, tier="t2")
```

---

## Production Deployment

```bash
# Systemd service
sudo cp deploy/production/prsm-node.service /etc/systemd/system/
sudo cp deploy/production/prsm.env.template /opt/prsm/.env
sudo systemctl enable prsm-node && sudo systemctl start prsm-node

# Docker (2-node demo)
docker-compose -f docker/docker-compose.demo.yml up
```

See [Deployment Guide](deploy/production/DEPLOYMENT_GUIDE.md) for full instructions.

---

## Project Stats

| Metric | Value |
|--------|-------|
| Version | 1.7.0 |
| MCP Tools | 16 |
| SDKs | Python, JavaScript, Go |
| FTNS Token | [Base mainnet](https://basescan.org/address/0x5276a3756C85f2E9e46f6D34386167a209aa16e5) |
| Bootstrap | `wss://bootstrap1.prsm-network.com:8765` |
| License | MIT |

---

## Documentation

| Document | Description |
|----------|------------|
| [Getting Started](docs/GETTING_STARTED.md) | Install → configure → first query in 5 minutes |
| [Sovereign-Edge AI Spec](docs/SOVEREIGN_EDGE_AI_SPEC.md) | Phase 1 architecture (Rings 1-6) |
| [Confidential Compute Spec](docs/CONFIDENTIAL_COMPUTE_SPEC.md) | Phase 2 architecture (Rings 7-10) |
| [Implementation Status](docs/IMPLEMENTATION_STATUS.md) | Subsystem status and test coverage |
| [Deployment Guide](deploy/production/DEPLOYMENT_GUIDE.md) | Production deployment walkthrough |
| [SDK Developer Guide](docs/SDK_DEVELOPER_GUIDE.md) | Building on PRSM |

---

## Contributing

```bash
git clone https://github.com/Ryno2390/PRSM.git
cd PRSM && pip install -e ".[dev]"
pytest --timeout=120    # Run test suite
```

See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.

---

**License:** MIT | **Website:** [prsm-network.com](https://www.prsm-network.com) | **PyPI:** [prsm-network](https://pypi.org/project/prsm-network/)
