Skip to content

tools

Tool Inventory Router.

This module contains the API routes for managing tools in the tool inventory. It provides endpoints for creating, reading, and updating tools.

create_tool async

create_tool(tool: ToolCreate) -> Tool

Create a new tool.

Parameters:

Name Type Description Default
tool ToolCreate

The tool creation model.

required

Returns:

Type Description
Tool

The created tool.

Source code in src/tool_inventory/routers/tools.py
@router.post(
    "/",
    status_code=status.HTTP_201_CREATED,
    summary="Create a tool",
)
async def create_tool(
    tool: ToolCreate,
) -> Tool:
    """Create a new tool.

    Args:
        tool: The tool creation model.

    Returns:
        The created tool.
    """
    with Session(engine) as session:
        db = Database(session)
        return db.create_tool(tool.to_model())

get_tool_by_id async

get_tool_by_id(tool_id: UUID) -> Tool

Get a tool by its ID.

Parameters:

Name Type Description Default
tool_id UUID

The UUID of the tool.

required

Returns:

Type Description
Tool

The tool with the specified ID.

Source code in src/tool_inventory/routers/tools.py
@router.get(
    "/{tool_id}",
    summary="Get a tool by ID",
)
async def get_tool_by_id(
    tool_id: UUID,
) -> Tool:
    """Get a tool by its ID.

    Args:
        tool_id: The UUID of the tool.

    Returns:
        The tool with the specified ID.
    """
    with Session(engine) as session:
        db = Database(session)
        return db.get_tool_by_id(tool_id)

get_tools async

get_tools(name: str | None = None) -> list[Tool]

Get tools by name.

Parameters:

Name Type Description Default
name str | None

The name of the tool to filter by.

None

Returns:

Type Description
list[Tool]

A list of tools.

Source code in src/tool_inventory/routers/tools.py
@router.get(
    "/",
    summary="Get tools",
)
async def get_tools(
    name: str | None = None,
) -> list[Tool]:
    """Get tools by name.

    Args:
        name: The name of the tool to filter by.

    Returns:
        A list of tools.
    """
    with Session(engine) as session:
        db = Database(session)
        return db.get_tools(name=name)

update_tool async

update_tool(tool_id: UUID, tool_patch: ToolPatch) -> Tool

Update an existing tool.

Parameters:

Name Type Description Default
tool_id UUID

The UUID of the tool to update.

required
tool_patch ToolPatch

The tool patch model.

required

Returns:

Type Description
Tool

The updated tool.

Source code in src/tool_inventory/routers/tools.py
@router.patch(
    "/{tool_id}",
    summary="Update a tool",
)
async def update_tool(
    tool_id: UUID,
    tool_patch: ToolPatch,
) -> Tool:
    """Update an existing tool.

    Args:
        tool_id: The UUID of the tool to update.
        tool_patch: The tool patch model.

    Returns:
        The updated tool.
    """
    with Session(engine) as session:
        db = Database(session)
        tool = db.get_tool_by_id(tool_id)
        tool_patch.patch(tool)
        return db.update_tool(tool)