Skip to main content

Prefect Blocks for authentication and connection management

Project description

dochain-block

Prefect Blocks for authentication and connection management.

Overview

dochain-block is a Prefect Block distribution package that provides reusable authentication and connection blocks for various services. The project is designed with a modular architecture to easily add new authentication modules.

Features

  • Modular Authentication Blocks: Each service has its own dedicated authentication block
  • Secure Credential Management: Built on Prefect's secure block system
  • Multiple Authentication Methods: Support for username/password, API keys, tokens, and more
  • Async-First Design: Optimized for Prefect's async execution model
  • Easy Integration: Seamless integration with Prefect flows and deployments

Installation

# Create virtual environment
uv venv
source .venv/bin/activate  # Unix/macOS
# or
.\.venv\Scripts\activate   # Windows

# Install the package
uv pip install -e .

Available Authentication Blocks

NacosBlock

Connect to Nacos service discovery and configuration management platform.

Supported Authentication Methods:

  • Username/Password
  • Access Key/Secret Key
  • Bearer Token

Features:

  • Configuration management
  • Service discovery
  • Health checks
  • Namespace support

Usage Example

from prefect import flow
from dochain_block import NacosBlock

@flow
def nacos_config_flow():
    # Load Nacos block
    nacos = NacosBlock.load("my-nacos-connection")

    # Get configuration
    config = asyncio.run(nacos.get_config("app-config", "DEFAULT_GROUP"))
    return config

# Save block configuration
nacos_block = NacosBlock(
    name="my-nacos-connection",
    server_url="http://localhost:8848/nacos",
    username="nacos",
    password="nacos",
    namespace="public"
)

nacos_block.save("my-nacos-connection")

Development

Adding New Authentication Modules

  1. Create a new module in src/dochain_block/auth/
  2. Inherit from AuthBlock base class
  3. Implement required methods:
    • authenticate(): Main authentication logic
    • Optional: validate_credentials(), refresh_credentials()
  4. Register the block in __init__.py

Example: New Authentication Module

from ..core.base_block import AuthBlock
from pydantic import Field, SecretStr

class MyServiceBlock(AuthBlock):
    """Authentication block for MyService"""

    api_key: SecretStr = Field(..., description="API key for MyService")
    base_url: str = Field(..., description="Base URL for MyService")

    _block_type_name = "MyService Authentication"

    async def authenticate(self, **kwargs):
        # Implement authentication logic
        return {
            "authenticated": True,
            "access_token": "your-token"
        }

Development Commands

# Install development dependencies
uv add --dev pytest pytest-asyncio pytest-cov

# Run tests
uv run pytest

# Run tests with coverage
uv run pytest --cov=dochain_block

# Run example
uv run python examples/nacos_example.py

Requirements

  • Python 3.11+
  • Prefect >= 3.4.24
  • Pydantic >= 2.12.3
  • httpx >= 0.28.1

License

[Add your license information here]

Contributing

[Add contribution guidelines here]

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

dochain_block-0.1.0.tar.gz (212.2 kB view details)

Uploaded Source

Built Distribution

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

dochain_block-0.1.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file dochain_block-0.1.0.tar.gz.

File metadata

  • Download URL: dochain_block-0.1.0.tar.gz
  • Upload date:
  • Size: 212.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.5

File hashes

Hashes for dochain_block-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3b5039a73a2103053c35a81d4ecb4fd1e3f1ac5e33052b84216d2154e06aa2f8
MD5 ba46cd4a0075c205f75bc01e6764373d
BLAKE2b-256 8fd470e97dd3bc607aaafe73e75ca899ec1816561f6df29d32d65e8e93fa8ca7

See more details on using hashes here.

File details

Details for the file dochain_block-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dochain_block-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 997a6b5acb578359a46102c3568491d3539a1a4d07a9942e1c16b80661f021ed
MD5 8214e31c5a7336a591c23add14b61729
BLAKE2b-256 eadf2cda8f9aa1e036520d5f73d86caadddadaaec5c61422ed82647e52bd4af3

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