Skip to content

docs/reference.md

python_app_template.app

get_pokemon(number=Path(title='The Pokemon to get (based on number)', ge=1, le=151))

Endpoint that returns information about pokemon. Args: number: The id of the pokemon to get Returns: Awesome information about the pokemon

Source code in src/python_app_template/app.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@app.get(path="/{number}", status_code=status.HTTP_200_OK)
def get_pokemon(
    number: int = Path(title="The Pokemon to get (based on number)", ge=1, le=151)
) -> dict:
    """
    Endpoint that returns information about pokemon.
    Args:
        number: The id of the pokemon to get
    Returns:
        Awesome information about the pokemon
    """
    pokemon_url: str = f"https://pokeapi.co/api/v2/pokemon/{number}"

    try:
        response: Response = httpx.get(url=pokemon_url)
    except Exception:
        raise HTTPException(
            status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
            detail=f"Could not send a request to {pokemon_url}",
        )

    if response.status_code == status.HTTP_200_OK:
        return response.json()
    else:
        raise HTTPException(status_code=response.status_code, detail=response.text)

python_app_template.service

Provides several sample functions for testing the docstrings

bar(name='Mysterious Person')

Say hello to the user.

Parameters:

Name Type Description Default
name str

The name of the person to greet

'Mysterious Person'

Returns:

Type Description
str

A string with a greeting

Source code in src/python_app_template/service.py
27
28
29
30
31
32
33
34
35
36
37
def bar(name: str = "Mysterious Person") -> str:
    """
    Say hello to the user.

    Args:
        name: The name of the person to greet

    Returns:
        A string with a greeting
    """
    return f"Hello {name}!"

foo(a, b)

Adds two numbers together

Examples:

>>> foo(a=1, b=2)
3
>>> foo(b=2, a=13)
15

Parameters:

Name Type Description Default
a int

The first number to add

required
b int

The second number to add

required

Returns:

Type Description
int

The sum of a and b

Source code in src/python_app_template/service.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def foo(a: int, b: int) -> int:
    """
    Adds two numbers together

    Examples:
        >>> foo(a=1, b=2)
        3
        >>> foo(b=2, a=13)
        15


    Args:
        a: The first number to add
        b: The second number to add

    Returns:
        The sum of a and b
    """
    return a + b