Metadata-Version: 2.4
Name: pymempool
Version: 0.3.0
Summary: Python Api for mempool.space
Author-email: Holger Nahrstaedt <nahrstaedt@gmail.com>
License: MIT License
        
        Copyright (c) 2022 Holger Nahrstaedt
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/holgern/pymempool
Keywords: mempool,btc
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.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >3.8.0
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: urllib3
Requires-Dist: typer
Requires-Dist: rich
Requires-Dist: requests
Requires-Dist: websockets
Dynamic: license-file

# pymempool

[![codecov](https://codecov.io/gh/holgern/pymempool/graph/badge.svg?token=VyIU0ZxwpD)](https://codecov.io/gh/holgern/pymempool)
[![PyPi Version](https://img.shields.io/pypi/v/pymempool.svg)](https://pypi.python.org/pypi/pymempool/)

Python wrapper and terminal dashboard for the [mempool.space](https://mempool.space) API.

## Installation

PyPI:

```bash
pip install pymempool
```

From source:

```bash
git clone https://github.com/holgern/pymempool.git
cd pymempool
python -m pip install -e .
```

## Quick Start

```python
from pymempool import MempoolAPI, RecommendedFees

mp = MempoolAPI()

fees = RecommendedFees(mp.get_recommended_fees_precise())
print(fees.as_dict())

mempool = mp.get_mempool()
print(mempool["count"], mempool["vsize"])

projected_blocks = mp.get_mempool_blocks_fee()
print(projected_blocks[0]["medianFee"])
```

## Best First Commands

```bash
pymempool overview
pymempool pressure
pymempool ladder
pymempool watch
```

## CLI Commands

```bash
# One-screen mempool dashboard
pymempool overview --precise-fees --blocks 6

# Fee pressure across human-readable bands
pymempool pressure

# Decision-first projected block ladder
pymempool ladder --limit 8

# Legacy ASCII mempool blocks view
pymempool mempool-blocks --limit 4

# Live mempool dashboard
pymempool watch --rbf fullRbf

# Stream raw websocket events
pymempool stream --want stats --want mempool-blocks
```

For command details:

```bash
pymempool --help
pymempool overview --help
```

## API Highlights

```python
from pymempool import MempoolAPI, MempoolWebSocketClient

mp = MempoolAPI()

rounded = mp.get_recommended_fees()
precise = mp.get_recommended_fees_precise()
recent = mp.get_mempool_recent()
audit = mp.get_block_audit_summary("<block_hash>")

client = MempoolWebSocketClient(want_data=["stats", "mempool-blocks"])
print(client.build_subscription_payloads())
```

## Rate Limiting

`pymempool` now treats HTTP `429 Too Many Requests` as back-pressure instead of a
generic fast retry. The client:

- rate-limits itself before sending REST requests with conservative per-host defaults
- honors integer `Retry-After` headers when present
- applies exponential backoff with jitter when `Retry-After` is absent
- keeps cooldown state per host so failover stays resilient without turning into rate-limit evasion
- reuses short-lived cached snapshots for hot endpoints like fees, mempool summary, and projected blocks
- prefers WebSocket flows for live dashboards so `watch` and `stream` do not depend on tight REST polling

You can tune the policy via `MempoolAPI(...)`:

```python
from pymempool import MempoolAPI

mp = MempoolAPI(
    rate_limit_per_sec=1.0,
    rate_limit_burst=5,
    respect_retry_after=True,
    enable_response_cache=True,
    cache_ttl_seconds=3.0,
)
```

## Development

Install dev and test dependencies:

```bash
uv pip install -r requirements.txt -r requirements-test.txt
```

Common checks:

```bash
pytest
pre-commit run --show-diff-on-failure --color=always --all-files
mypy pymempool
python docs/make.py
```

## Documentation

- REST API reference: https://mempool.space/docs/api/rest
- Project docs: `docs/`

## License

[MIT](https://choosealicense.com/licenses/mit/)
