haondt-athena


Namehaondt-athena JSON
Version 1.2.0 PyPI version JSON
download
home_pagehttps://github.com/haondt/athena
Summarya file-based rest api client
upload_time2024-03-09 02:54:12
maintainer
docs_urlNone
authorhaondt
requires_python>=3.11,<4.0
licenseMIT
keywords api rest
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # athena

athena is a file-based rest api client.

# Usage

athena can be run as a module, or with the included binary.

```sh
python3 -m athena --help

athena --help
```

## Setup

Start by running the init in your project directory.

```sh
athena init .
```

Enter this directory, and create a workspace

```sh
cd athena
athena create workspace my-workspace
```

Lastly, create a new collection inside the workspace

```sh
athena create collection my-collection -w my-workspace
```

## Creating tests

To create a test case, add a python file in the `run` folder of a collection

```sh
vim athena/my-workspace/collections/my-collection/run/hello.py
```

Create a function called `run`, that takes the `Athena` instance as the argument.

```python
from athena.client import Athena

def run(athena: Athena):
    ...
```

## Sending requests

The injected `Athena` instance provides methods to create and send requests. Start by creating a new `Client`.

```python
def run(athena: Athena):
    client = athena.client()
```

The client can be configured by providing a builder function. The builder will be applied to each request sent by the client.

```python
def run(athena: Athena):
    client = athena.client(lambda builder: builder
        .base_url("http://haondt.com/api/")
        .header("origin", "athena")
        .auth.bearer("some_secret_key"))

```

The client can be used to send api requests. The requets themselves can also be configured with a builder.

```python
def run(athena: Athena):
    ...
    response = client.put("planets/saturn", lambda builder: builder
        .body.json({
            "diameter": "120 thousand km",
            "density": "687 kg/m^3",
            "distance_from_sun": "1.35 billion km"
        }))
```

The response is a `ResponseTrace`, which contains information about the response

```python
def run(athena: Athena):
    ...
    print(f"status: {response.status_code} {response.reason}")
```

athena can provide more information about the rest of the request with the `trace` method, which will return the `AthenaTrace` for the whole request/response saga.

```python
def run(athena: Athena):
    ...
    trace = athena.trace(response)
    print(f"request payload: {trace.request.raw}")
    print(f"request time: {trace.elapsed}")
```

## Running tests

athena can search the directory for modules to execute. Use `athena run` to start, and provide an argument of the module to run.
This can be a path to the module or to a directory along the module hierarchy. In the latter case, athena will run all the modules
it can find inside that directory.

```sh
# run all the modules inside the api directory
athena run /path/to/athena/my-workspace/collections/my-collection/run/api
```

### Module keys

Any command that takes a module path can also take an argument of the form `workspace:collection:module`, and run all the modules that match.
This key will be computed relative to the current working directory, and allows for more precision in determining which modules to run.

```sh
# run all modules in "my-workspace" named "hello.py"
athena run "my-workspace:*:hello"
```

For any module in a collection `run` folder, the directory path relative to the `run` folder will make up the module name. 
For example, given the following files:

```
athena/my-workspace/collections/my-collection/run/red.py
athena/my-workspace/collections/my-collection/run/green.py
athena/my-workspace/collections/my-collection/run/toast/blue.py
athena/my-workspace/collections/my-second-collection/run/red.py
```

You would have the following module keys:

```
my-workspace:my-collection:red
my-workspace:my-collection:green
my-workspace:my-collection:toast.blue
my-workspace:my-second-collection:red
```

The workspace and collection parts can contain wild cards. A single period (`.`) in either field will use the current directory.
A single asterisk (`*`) will use all directories.

```sh
# run all modules in "my-workspace" named "hello.py"
athena run "my-workspace:*:hello"
```

For the module name, asterisks can be used to denote "any module/directory", and double asterisks (`**`) can be used to denote any subdirectory.

```sh
# runs all files
athena run "*:*:**"

# runs red.py and green.py
athena run "*:*:*"

# runs only blue.py
athena run "*:*:*.*"
athena run "*:*:toast.*"
athena run "*:*:**blue"

# run all modules in the collection of the current directory
athena run ".:.:**"
```

Internally, asterisks are compiled into the regular expression `[^.]+` and double asterisks are compiled into `.+`.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/haondt/athena",
    "name": "haondt-athena",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11,<4.0",
    "maintainer_email": "",
    "keywords": "api,rest",
    "author": "haondt",
    "author_email": "",
    "download_url": "",
    "platform": null,
    "description": "# athena\n\nathena is a file-based rest api client.\n\n# Usage\n\nathena can be run as a module, or with the included binary.\n\n```sh\npython3 -m athena --help\n\nathena --help\n```\n\n## Setup\n\nStart by running the init in your project directory.\n\n```sh\nathena init .\n```\n\nEnter this directory, and create a workspace\n\n```sh\ncd athena\nathena create workspace my-workspace\n```\n\nLastly, create a new collection inside the workspace\n\n```sh\nathena create collection my-collection -w my-workspace\n```\n\n## Creating tests\n\nTo create a test case, add a python file in the `run` folder of a collection\n\n```sh\nvim athena/my-workspace/collections/my-collection/run/hello.py\n```\n\nCreate a function called `run`, that takes the `Athena` instance as the argument.\n\n```python\nfrom athena.client import Athena\n\ndef run(athena: Athena):\n    ...\n```\n\n## Sending requests\n\nThe injected `Athena` instance provides methods to create and send requests. Start by creating a new `Client`.\n\n```python\ndef run(athena: Athena):\n    client = athena.client()\n```\n\nThe client can be configured by providing a builder function. The builder will be applied to each request sent by the client.\n\n```python\ndef run(athena: Athena):\n    client = athena.client(lambda builder: builder\n        .base_url(\"http://haondt.com/api/\")\n        .header(\"origin\", \"athena\")\n        .auth.bearer(\"some_secret_key\"))\n\n```\n\nThe client can be used to send api requests. The requets themselves can also be configured with a builder.\n\n```python\ndef run(athena: Athena):\n    ...\n    response = client.put(\"planets/saturn\", lambda builder: builder\n        .body.json({\n            \"diameter\": \"120 thousand km\",\n            \"density\": \"687 kg/m^3\",\n            \"distance_from_sun\": \"1.35 billion km\"\n        }))\n```\n\nThe response is a `ResponseTrace`, which contains information about the response\n\n```python\ndef run(athena: Athena):\n    ...\n    print(f\"status: {response.status_code} {response.reason}\")\n```\n\nathena can provide more information about the rest of the request with the `trace` method, which will return the `AthenaTrace` for the whole request/response saga.\n\n```python\ndef run(athena: Athena):\n    ...\n    trace = athena.trace(response)\n    print(f\"request payload: {trace.request.raw}\")\n    print(f\"request time: {trace.elapsed}\")\n```\n\n## Running tests\n\nathena can search the directory for modules to execute. Use `athena run` to start, and provide an argument of the module to run.\nThis can be a path to the module or to a directory along the module hierarchy. In the latter case, athena will run all the modules\nit can find inside that directory.\n\n```sh\n# run all the modules inside the api directory\nathena run /path/to/athena/my-workspace/collections/my-collection/run/api\n```\n\n### Module keys\n\nAny command that takes a module path can also take an argument of the form `workspace:collection:module`, and run all the modules that match.\nThis key will be computed relative to the current working directory, and allows for more precision in determining which modules to run.\n\n```sh\n# run all modules in \"my-workspace\" named \"hello.py\"\nathena run \"my-workspace:*:hello\"\n```\n\nFor any module in a collection `run` folder, the directory path relative to the `run` folder will make up the module name. \nFor example, given the following files:\n\n```\nathena/my-workspace/collections/my-collection/run/red.py\nathena/my-workspace/collections/my-collection/run/green.py\nathena/my-workspace/collections/my-collection/run/toast/blue.py\nathena/my-workspace/collections/my-second-collection/run/red.py\n```\n\nYou would have the following module keys:\n\n```\nmy-workspace:my-collection:red\nmy-workspace:my-collection:green\nmy-workspace:my-collection:toast.blue\nmy-workspace:my-second-collection:red\n```\n\nThe workspace and collection parts can contain wild cards. A single period (`.`) in either field will use the current directory.\nA single asterisk (`*`) will use all directories.\n\n```sh\n# run all modules in \"my-workspace\" named \"hello.py\"\nathena run \"my-workspace:*:hello\"\n```\n\nFor the module name, asterisks can be used to denote \"any module/directory\", and double asterisks (`**`) can be used to denote any subdirectory.\n\n```sh\n# runs all files\nathena run \"*:*:**\"\n\n# runs red.py and green.py\nathena run \"*:*:*\"\n\n# runs only blue.py\nathena run \"*:*:*.*\"\nathena run \"*:*:toast.*\"\nathena run \"*:*:**blue\"\n\n# run all modules in the collection of the current directory\nathena run \".:.:**\"\n```\n\nInternally, asterisks are compiled into the regular expression `[^.]+` and double asterisks are compiled into `.+`.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "a file-based rest api client",
    "version": "1.2.0",
    "project_urls": {
        "Documentation": "https://github.com/haondt/athena/blob/main/README.md",
        "Homepage": "https://github.com/haondt/athena",
        "Repository": "https://github.com/haondt/athena"
    },
    "split_keywords": [
        "api",
        "rest"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "bbee57364d8a0aca682b330210ea4f7234c5ae2d7abe5ac65d878ad6c0e6b868",
                "md5": "2c8e09d20c4a98bcadf7f8d4e5099bb4",
                "sha256": "81f368a9e2d147d852ec666adc6c1b67eebd1c2331938664b8064ae19f3c7bb1"
            },
            "downloads": -1,
            "filename": "haondt_athena-1.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2c8e09d20c4a98bcadf7f8d4e5099bb4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11,<4.0",
            "size": 26526,
            "upload_time": "2024-03-09T02:54:12",
            "upload_time_iso_8601": "2024-03-09T02:54:12.122818Z",
            "url": "https://files.pythonhosted.org/packages/bb/ee/57364d8a0aca682b330210ea4f7234c5ae2d7abe5ac65d878ad6c0e6b868/haondt_athena-1.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-09 02:54:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "haondt",
    "github_project": "athena",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "haondt-athena"
}
        
Elapsed time: 0.20834s