Skip to main content

Professional Python development tools for async/await analysis and code quality

Project description

Kairix DevTools

Tests Coverage Python PyPI version License: Unlicense Code style: black Checked with mypy

๐Ÿš€ Professional Python development tools for async/await analysis, code quality, and CI/CD integration.

A comprehensive CLI library for development tools that can be used with pre-commit hooks, manually, or in CI/CD pipelines.

๐Ÿš€ Quick Start

# Install
pip install kairix-devtools

# Check async/await usage in your code
kairix-devtools asyncio check-await src/

# Get JSON output for tooling integration
kairix-devtools asyncio check-await src/ --output-format json

๐Ÿ“‹ Features

๐Ÿ”„ Asyncio Analysis Tools

Advanced async/await validation that helps you catch common async programming mistakes:

  • โœ… Missing await detection - Finds async functions called without await
  • โœ… Missing asyncio context - Detects async functions called outside async context
  • โœ… Smart asyncio.gather handling - Correctly handles coroutines passed to gather()
  • โœ… Type-aware analysis - Respects functions typed to return coroutines
  • โœ… Comprehensive reporting - Human-friendly and JSON output formats

๐Ÿ“– Documentation

๐Ÿ’ก Common Use Cases

1. Pre-commit Hook

Catch async/await issues before they reach your repository:

# .pre-commit-config.yaml
repos:
  - repo: local
    hooks:
      - id: check-async-await
        name: Check async/await usage
        entry: kairix-devtools asyncio check-await
        language: system
        files: \.py$
        args: ["--output-format", "human"]

2. CI/CD Integration

GitHub Actions example:

name: Code Quality

on: [push, pull_request]

jobs:
  async-check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: '3.12.x'
      - name: Install kairix-devtools
        run: pip install kairix-devtools
      - name: Check async/await usage
        run: kairix-devtools asyncio check-await src/ --output-format json

3. Local Development

Quick checks during development:

# Check specific file
kairix-devtools asyncio check-await my_async_module.py

# Check directory with exclusions
kairix-devtools asyncio check-await src/ --exclude "test_*" --exclude "*_legacy.py"

# JSON output for further processing
kairix-devtools asyncio check-await src/ --output-format json | jq '.violations | length'

๐ŸŽฏ Practical Examples

โŒ Issues Detected

# Missing await in async function
async def fetch_user_data():
    user = get_user_async()  # โŒ Missing await
    return user

# Missing asyncio context in sync function  
def main():
    result = fetch_user_data()  # โŒ Missing asyncio.run()
    return result

# Unhandled coroutine
async def process_data():
    fetch_data_async()  # โŒ Created but never awaited
    return "done"

โœ… Correct Patterns Recognized

# Proper asyncio.gather usage
async def fetch_multiple():
    results = await asyncio.gather(
        fetch_data_async("A"),  # โœ… Handled by gather
        fetch_data_async("B")   # โœ… Handled by gather
    )
    return results

# Functions typed to return coroutines
def create_tasks() -> list[Coroutine[Any, Any, str]]:
    return [
        fetch_data_async("A"),  # โœ… Valid: function returns coroutines
        fetch_data_async("B")   # โœ… Valid: function returns coroutines
    ]

# Proper asyncio context
def main():
    result = asyncio.run(fetch_user_data())  # โœ… Correct
    return result

๐Ÿ”ง Programmatic API

Use kairix-devtools in your own Python tools:

from kairix_devtools.asyncio import AsyncChecker

# Create checker instance
checker = AsyncChecker()

# Check a single file
result = checker.check_file("my_async_code.py")

# Check a directory with exclusions
result = checker.check_directory(
    "src/", 
    exclude_patterns=["test_*", "*_test.py"]
)

# Access results
print(f"Files checked: {result.total_files}")
print(f"Issues found: {result.violation_count}")
print(f"All checks passed: {result.passed}")

# Process violations
for violation in result.violations:
    print(f"Issue in {violation.file_path}:{violation.line_number}")
    print(f"  Function: {violation.function_name}")
    print(f"  Type: {violation.violation_type}")
    print(f"  Code: {violation.source_line}")

# Convert to JSON for external tools
result_json = result.model_dump()

๐Ÿ“Š Output Formats

Human-Readable Output

โŒ Async/await violations found!

AsyncViolationError: Function 'fetch_data' called without proper async handling
  Type: missing_await
  ๐Ÿ’ก Fix: Add 'await' before the function call

๐Ÿ”„ File "example.py", line 15
    result = fetch_data("https://api.example.com")
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

๐Ÿ“ Files checked: 3
Violations found: ๐Ÿ”„ missing_await: 1
โŒ Check failed!

JSON Output

{
  "total_files": 3,
  "violations": [
    {
      "file_path": "example.py",
      "line_number": 15,
      "column_number": 13,
      "function_name": "fetch_data",
      "violation_type": "missing_await",
      "source_line": "    result = fetch_data(\"https://api.example.com\")"
    }
  ],
  "passed": false,
  "violation_count": 1
}

๐Ÿ› ๏ธ Installation & Development

Installation

# Install from PyPI (when published)
pip install kairix-devtools

# Install from source
git clone https://github.com/your-org/kairix-devtools.git
cd kairix-devtools
pip install -e .

Development Setup

# Install in development mode
pip install -e .

# Run tests
pytest tests/

# Run type checking
pyright kairix_devtools/

# Test the tool on itself
kairix-devtools asyncio check-await kairix_devtools/

๐Ÿค Contributing

We love contributions! There are many ways you can help:

๐Ÿš€ Ways to Contribute

  • ๐Ÿ› Report Bugs - Use our issue templates
  • โœจ Propose Features - Share your ideas to improve the tool
  • ๐Ÿ“š Improve Documentation - Help other users with better docs
  • ๐Ÿงช Write Tests - Improve code coverage and quality
  • ๐Ÿ”ง Development - Implement new features or fix bugs

๐Ÿ“‹ Quick Start for Contributors

# 1. Fork and clone the repository
git clone https://github.com/YOUR_USERNAME/devtools-python.git
cd devtools-python

# 2. Set up the development environment
# This project uses a devcontainer for a consistent development environment.
# Simply open the project in VS Code with the Dev Containers extension installed.

# If you prefer a manual setup:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -e ".[dev]"

# 3. Install pre-commit hooks
pre-commit install

# 4. Run tests to verify everything works
pytest

๐Ÿ“– Contributor Resources

๐Ÿ† Acknowledgments

We thank all our contributors who make this project possible. Their contributions are featured in:

  • GitHub's list of contributors
  • Release notes for significant changes
  • Special mentions for major contributions

๐Ÿ“„ License

This project is licensed under the Unlicense - see the LICENSE file for details.

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

kairix_devtools-25.6.5.tar.gz (19.3 kB view details)

Uploaded Source

Built Distribution

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

kairix_devtools-25.6.5-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file kairix_devtools-25.6.5.tar.gz.

File metadata

  • Download URL: kairix_devtools-25.6.5.tar.gz
  • Upload date:
  • Size: 19.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for kairix_devtools-25.6.5.tar.gz
Algorithm Hash digest
SHA256 e476cad8f701be962f799e94cda0dc37a13e56558eda058bc8dbc6078b75e6e5
MD5 9022269941fd59250da598bf2be97517
BLAKE2b-256 645863ab6f6faa3544ff68d35fca97c5f67274b073f40e57b2bdb2785097d491

See more details on using hashes here.

Provenance

The following attestation bundles were made for kairix_devtools-25.6.5.tar.gz:

Publisher: release.yml on kairix-dev/devtools-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kairix_devtools-25.6.5-py3-none-any.whl.

File metadata

File hashes

Hashes for kairix_devtools-25.6.5-py3-none-any.whl
Algorithm Hash digest
SHA256 94818c8af989e3740c589664180c80fc13b49ebafddeb3b85aee2ec1180af2b5
MD5 a5958743dbb23d741b606317d2f0f48b
BLAKE2b-256 c949a6ec75417805120b63b2405c41756b0c978580aefc645671df2a2f1ffaab

See more details on using hashes here.

Provenance

The following attestation bundles were made for kairix_devtools-25.6.5-py3-none-any.whl:

Publisher: release.yml on kairix-dev/devtools-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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