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.1.tar.gz (4.6 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.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for bloky-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d37957be232103696928394d06a24ce9608e485f432b87e3e894da7fd267e947
MD5 bbfc05017f42bb2c44bb311d6ae72888
BLAKE2b-256 80bbd0c508173331cec38184889c45b43b769ef40288e65d1b72ec2b3b4fa747

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for bloky-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e6d7ea25dd68f3d4008bcc10658ad53a905087b8eb871ed87a2787ed5b136202
MD5 6a97325ecc1605e47768aa41f9d18724
BLAKE2b-256 bae9923704af34de2935ec9aa0ed5a19338b5bb4fa43a21ddb819bc75368e9f2

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