DEV Community

Ali Esmaeili
Ali Esmaeili

Posted on • Originally published at aliesm-com.Medium on

perfometrics: A Lightweight Python Package for URL Performance Metrics

In the world of software performance and DevOps, having fast, actionable insights into your web service response times is critical. While there are heavy-duty monitoring tools available, sometimes you just want something dead-simple to test how a specific URL is performing —  that’s where perfometrics comes in.

Dark-themed banner showing the word ‘perfometrics’ with the subtitle ‘A Lightweight Python Package for URL Performance Metrics’ on the left, and a performance chart with rising bars and a Python logo on the right.

🔍 What is perfometrics?

perfometrics is a minimalistic Python package that lets you measure performance metrics for any HTTP/HTTPS URL , using nothing more than a couple of lines of code.

It’s built on top of pycurl, providing a clean API to track:

  • HTTP status code
  • DNS resolution time
  • TCP connection time
  • SSL/TLS handshake time
  • Time to First Byte (TTFB)
  • Data transfer time
  • Total request time

⚙️ Installation

You can install it directly from PyPI:‍

pip install perfometrics
Enter fullscreen mode Exit fullscreen mode

🚀 How to Use It

import perfometrics.curl as pcurl

url = 'https://example.com'
curl_uptime = pcurl.CurlUptime(url)
metrics = curl_uptime.get_metrics()

print('Metrics for', url)
print('HTTP status code:', metrics['status_code'])
print('Time taken for DNS resolution:', metrics['dns_lookup'], 'seconds')
print('Time taken for establishing TCP connection:', metrics['tcp'], 'seconds')
print('Time taken for SSL/TLS handshake:', metrics['ssl_tls'], 'seconds')
print('Time to First Byte (TTFB):', metrics['ttfb'], 'seconds')
print('Time taken for data transfer:', metrics['data_transfer'], 'seconds')
print('Total time taken for request:', metrics['total'], 'seconds')

curl_uptime.close_session()
Enter fullscreen mode Exit fullscreen mode

✅ The result gives you a breakdown of where your time is being spent in the connection process — ideal for debugging latency issues or verifying optimizations.

💡 Use Cases

  • DevOps Monitoring : Benchmark your production endpoints periodically
  • CI/CD Testing : Run it in your pipelines to ensure APIs respond within acceptable limits
  • Data Collection : Log metrics over time and analyze performance trends
  • Lightweight Health Checks : Build quick health monitors using this package

📦 What’s Inside

  • A single class: CurlUptime
  • One method: .get_metrics() returns a dictionary of timing values
  • Optional: .close_session() to clean up the curl handler

No need for extra config or YAMLs. Just import and measure.

📁 Source Code & Documentation

🧠 Final Thoughts

If you’re looking for a dead-simple way to collect performance metrics for your URLs in Python, without setting up a full observability stack, give perfometrics a try.

If you like it, I’d appreciate a ⭐ on GitHub, and feel free to submit issues or PRs with ideas!

Top comments (1)

Collapse
 
setareh_samami profile image
setareh samami

It’s worth trying