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.4.tar.gz (6.9 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.4-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kairix_devtools-25.6.4.tar.gz
  • Upload date:
  • Size: 6.9 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.4.tar.gz
Algorithm Hash digest
SHA256 370cbb7f0e35170769da2c75882e18b08946dffac09f4cf989c0cf40c28e9eed
MD5 c478c4a33fc7b8d0a55176937750b814
BLAKE2b-256 0134b79c8720d9372d6bc15e62cf77bf59c697f518d45cd3954a50c4cf2ee8f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for kairix_devtools-25.6.4.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.4-py3-none-any.whl.

File metadata

File hashes

Hashes for kairix_devtools-25.6.4-py3-none-any.whl
Algorithm Hash digest
SHA256 78bd6a5ee89c35f9f7ff392440fb1df3cea81a3b62d8f4042a0255af65388f0e
MD5 4bb769b665519b17e7d25b2837c06783
BLAKE2b-256 0220f20047a103f1d5b5b6063773e188bf2e39cec438155ff7d9a1f16a2a1cd2

See more details on using hashes here.

Provenance

The following attestation bundles were made for kairix_devtools-25.6.4-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