> For the complete documentation index, see [llms.txt](https://docs.agentipy.fun/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.agentipy.fun/tools/get-tps-transactions-per-second.md).

# Get TPS (Transactions Per Second)

The `Get TPS` tool, part of AgentiPy, is used to fetch and analyze Transactions Per Second (TPS) data from the Solana blockchain. It can retrieve current TPS and also track performance metrics over time.

## Functionality

The tool consists of a standalone function `fetch_performance_samples` and a class `SolanaPerformanceTracker`.

### Key Functions/Classes:

* `fetch_performance_samples(agent: SolanaAgentKit, sample_count: int = 1) -> List[NetworkPerformanceMetrics]`:
  * Asynchronously fetches a specified number of recent performance samples from the Solana network using `agent.connection.get_recent_performance_samples()`.
  * Each sample contains data like the number of transactions and the sample period.
  * Converts these samples into a list of `NetworkPerformanceMetrics` objects, which include calculated TPS, total transactions, sampling period, and current slot.
* `SolanaPerformanceTracker`:
  * **`__init__(self, agent: SolanaAgentKit)`**: Initializes the tracker with a `SolanaAgentKit` instance.
  * **`record_latest_metrics(self) -> NetworkPerformanceMetrics`**: Fetches the single latest performance sample using `fetch_performance_samples` and stores it in an internal `metrics_history`.
  * **`calculate_average_tps(self) -> Optional[float]`**: Calculates the average TPS from all metrics stored in `metrics_history`.
  * **`find_maximum_tps(self) -> Optional[float]`**: Finds the maximum TPS from the `metrics_history`.
  * **`reset_metrics_history(self) -> None`**: Clears the `metrics_history`.
  * **`fetch_current_tps(agent: SolanaAgentKit) -> float`** (static method): A static method to quickly fetch the current TPS based on the latest single performance sample. This is likely the most commonly used function for a quick TPS check.

##

## Source Code

You can find the source code for this tool on GitHub: <https://github.com/niceberginc/agentipy/blob/main/agentipy/tools/get_tps.py>
