TL;DR: Stop wasting time writing complex
astlogic. Use the Prometheus Text & Code Toolkit API to analyze Python code complexity and structure in milliseconds. It's free for developers.
As Python developers, we often build tools that need to analyze code. Maybe you're building:
- A student grading system ๐
- A code quality checker โ
- A customized linter ๐งน
The standard way involves importing the ast module, visiting nodes, handling recursion, and dealing with edge cases. It's painful and time-consuming.
Today, I'm sharing a tool I built to solve this: Prometheus Text & Code Toolkit.
What is it? ๐ค
It's a serverless API that does the heavy lifting for you.
- Code Analysis: Instantly get cyclomatic complexity, function counts, classes, and imports from raw Python code.
- Text Tools: Extract keywords, calculate reading time (e.g. for blog posts), and generate slugs.
Best part? It's completely FREE for developers. (500 calls/month)
How to use it? ๐
1. Get a Key
Go to RapidAPI - Prometheus Toolkit, subscribe to the Basic Plan (Free).
2. The Code
Here is how you check if a piece of code is too complex:
import requests
url = "https://prometheus-text-and-code-toolkit.p.rapidapi.com/api/explain"
# The code you want to analyze
my_code = """
def complex_function():
if True:
for i in range(10):
print(i)
"""
payload = {
"code": my_code,
"language": "python"
}
headers = {
"x-rapidapi-key": "YOUR_API_KEY_HERE",
"x-rapidapi-host": "prometheus-text-and-code-toolkit.p.rapidapi.com",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
# ๐ Use this to fail a CI/CD pipeline if code is too messy!
print(response.json())
3. The Result
{
"functions": [
{
"name": "complex_function",
"lineno": 1,
"args": []
}
],
"complexity": 3,
"classes": [],
"imports": []
}
Why use this API? ๐ก
- Privacy First: It's a static analysis engine. It processes your code in RAM and forgets it instantly. No storage.
- Zero Dependencies: You don't need to install heavy libraries locally.
- Fast: Built on Vercel Edge functions for low latency.
๐ Try it now: Prometheus Toolkit on RapidAPI
If you find this useful, please leave a generic comment or a โค๏ธ! It helps a lot.
Top comments (0)