Skip to main content

Analyzes Python code to detect blocking operations

Project description

Bloky

A Python tool that analyzes Python code to detect blocking operations that could impact performance in async contexts.

Features

  • Boto3 Detection: Identifies synchronous boto3 client calls
  • Database Session Detection: Finds usage of synchronous Session instead of AsyncSession
  • File Operations: Detects blocking file I/O operations
  • Network Calls: Identifies synchronous HTTP requests
  • Recursive Scanning: Analyzes all Python files in directories and subdirectories
  • Detailed Reporting: Provides comprehensive reports with code snippets

Installation

Install from source (development)

pip install -e .

Install from PyPI (when published)

pip install bloky

Usage

After installation, you can use the bloky command from anywhere:

Analyze a directory

bloky /path/to/your/project

Analyze a single file

bloky /path/to/file.py

Save report to file

bloky /path/to/project --output blocking_report.txt

Alternative: Run directly without installation

python main.py /path/to/your/project

Detected Issues

The analyzer detects several types of blocking operations:

  1. boto3_sync_call: Synchronous boto3 client calls
  2. potential_boto3_sync: Potential boto3 operations
  3. sync_session_usage: Using Session instead of AsyncSession
  4. sync_db_operation: Synchronous database operations
  5. sync_file_operation: Blocking file I/O
  6. sync_network_call: Synchronous HTTP requests

Example Output

🚨 BLOCKING OPERATIONS DETECTED
==================================================

SUMMARY:
  boto3_sync_call: 2 occurrences
  sync_session_usage: 1 occurrences

BOTO3 SYNC CALL:
------------------------------
  📍 /path/to/file.py:15
     Synchronous boto3 client call detected
     Code: scheduler = get_boto_client("scheduler")
            target = {"Arn": arn, "Input": state_input, "RoleArn": role_arn}
            schedule = scheduler.create_schedule(

SYNC SESSION USAGE:
------------------------------
  📍 /path/to/file.py:45
     Using synchronous Session instead of AsyncSession
     Code: def playbook_list_get(
            self,
            request: Request,
            satori_db: Session,

Examples of Detected Patterns

Boto3 Synchronous Calls

# This will be detected
scheduler = get_boto_client("scheduler")
schedule = scheduler.create_schedule(...)

Database Session Issues

# This will be detected - using Session instead of AsyncSession
def some_function(self, satori_db: Session):
    result = satori_db.query(Model).all()

File Operations

# This will be detected
with open('file.txt') as f:
    content = f.read()  # Blocking read operation

Network Calls

# This will be detected
import requests
response = requests.get('https://api.example.com')  # Blocking HTTP call

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bloky-0.1.2.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bloky-0.1.2-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file bloky-0.1.2.tar.gz.

File metadata

  • Download URL: bloky-0.1.2.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.5

File hashes

Hashes for bloky-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f918743dcaf045b44471f5ab692c0fb91ee57696d69de32bcc51fed8793fb6dc
MD5 81fd152d4388ecfa4ed557c5f69098c6
BLAKE2b-256 baa38b8895074376d4852f9bb91ed4d7e2dd8d27b0a3ed88bd73313bf84dbf4e

See more details on using hashes here.

File details

Details for the file bloky-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: bloky-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.5

File hashes

Hashes for bloky-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7397494bc1aa46fae46f75a19d95d54189e9ab22cf795164c69fc81678f1583e
MD5 fdb66183d5445253647a3e854485138a
BLAKE2b-256 0033c7366287b2cd4437ad0da3fed34cd6e0401577461e9da2b914f844c8cfed

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page