Skip to content

Reserve

reserve

InitReserveTool — reserve a PyPI package name as an AXMTool.

InitReserveTool

Reserve a package name on PyPI.

Registered as init_reserve via axm.tools entry point.

Source code in packages/axm-init/src/axm_init/tools/reserve.py
Python
class InitReserveTool:
    """Reserve a package name on PyPI.

    Registered as ``init_reserve`` via axm.tools entry point.
    """

    @property
    def name(self) -> str:
        """Tool name used for MCP registration."""
        return "init_reserve"

    def execute(
        self,
        name: str = "",
        *,
        author: str = "",
        email: str = "",
        dry_run: bool = False,
        json_output: bool = False,
    ) -> ToolResult:
        """Reserve a package name on PyPI.

        Args:
            name: Package name to reserve.
            author: Author name for the placeholder package.
            email: Author email for the placeholder package.
            dry_run: If True, skip the actual publish step.
            json_output: If True, render the structured report.

        Returns:
            ToolResult with reservation status.
        """
        validated = _validate_reserve_inputs(name, author, email, dry_run)
        if isinstance(validated, ToolResult):
            return _apply_json_output(validated, json_output)
        author, email = validated

        try:
            from axm_init.adapters.pypi import PyPIAdapter
            from axm_init.core.reserver import reserve_pypi

            token = _resolve_pypi_token(dry_run)
            if isinstance(token, ToolResult):
                return _apply_json_output(token, json_output)

            result = reserve_pypi(
                name=name,
                author=author,
                email=email,
                token=token,
                dry_run=dry_run,
                checker=PyPIAdapter(),
            )

            return _apply_json_output(
                ToolResult(
                    success=result.success,
                    data={
                        "package_name": result.package_name,
                        "version": result.version,
                        "message": result.message,
                    },
                    text=(
                        _render_reserve_text(
                            result.package_name, result.version, result.message
                        )
                        if result.success
                        else None
                    ),
                    error=None if result.success else result.message,
                ),
                json_output,
            )
        except Exception as exc:
            return _apply_json_output(
                ToolResult(success=False, error=str(exc)), json_output
            )
name property

Tool name used for MCP registration.

execute(name='', *, author='', email='', dry_run=False, json_output=False)

Reserve a package name on PyPI.

Parameters:

Name Type Description Default
name str

Package name to reserve.

''
author str

Author name for the placeholder package.

''
email str

Author email for the placeholder package.

''
dry_run bool

If True, skip the actual publish step.

False
json_output bool

If True, render the structured report.

False

Returns:

Type Description
ToolResult

ToolResult with reservation status.

Source code in packages/axm-init/src/axm_init/tools/reserve.py
Python
def execute(
    self,
    name: str = "",
    *,
    author: str = "",
    email: str = "",
    dry_run: bool = False,
    json_output: bool = False,
) -> ToolResult:
    """Reserve a package name on PyPI.

    Args:
        name: Package name to reserve.
        author: Author name for the placeholder package.
        email: Author email for the placeholder package.
        dry_run: If True, skip the actual publish step.
        json_output: If True, render the structured report.

    Returns:
        ToolResult with reservation status.
    """
    validated = _validate_reserve_inputs(name, author, email, dry_run)
    if isinstance(validated, ToolResult):
        return _apply_json_output(validated, json_output)
    author, email = validated

    try:
        from axm_init.adapters.pypi import PyPIAdapter
        from axm_init.core.reserver import reserve_pypi

        token = _resolve_pypi_token(dry_run)
        if isinstance(token, ToolResult):
            return _apply_json_output(token, json_output)

        result = reserve_pypi(
            name=name,
            author=author,
            email=email,
            token=token,
            dry_run=dry_run,
            checker=PyPIAdapter(),
        )

        return _apply_json_output(
            ToolResult(
                success=result.success,
                data={
                    "package_name": result.package_name,
                    "version": result.version,
                    "message": result.message,
                },
                text=(
                    _render_reserve_text(
                        result.package_name, result.version, result.message
                    )
                    if result.success
                    else None
                ),
                error=None if result.success else result.message,
            ),
            json_output,
        )
    except Exception as exc:
        return _apply_json_output(
            ToolResult(success=False, error=str(exc)), json_output
        )