agave


Nameagave JSON
Version 1.4.0 PyPI version JSON
download
home_pagehttps://github.com/cuenca-mx/agave
SummaryRest_api
upload_time2025-04-09 01:26:38
maintainerNone
docs_urlNone
authorCuenca
requires_python>=3.9
licenseNone
keywords
VCS
bugtrack_url
requirements boto3 types-boto3 cuenca-validations chalice mongoengine fastapi mongoengine-plus python-multipart pydantic starlette starlette-context aiobotocore types-aiobotocore-sqs
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # agave
[![test](https://github.com/cuenca-mx/agave/workflows/test/badge.svg)](https://github.com/cuenca-mx/agave/actions?query=workflow%3Atest)
[![codecov](https://codecov.io/gh/cuenca-mx/agave/branch/main/graph/badge.svg)](https://codecov.io/gh/cuenca-mx/agave)
[![PyPI](https://img.shields.io/pypi/v/agave.svg)](https://pypi.org/project/agave/)

Agave is a library for building REST APIs using a Blueprint pattern, with support for both AWS Chalice and FastAPI frameworks. It simplifies the creation of JSON-based endpoints for querying, modifying, and creating resources.

## Installation

Choose the installation option based on your framework:

### Chalice Installation

```bash
pip install agave[chalice]
```

### FastAPI Installation

```bash
pip install agave[fastapi]
```

### SQS task support:
```bash
pip install agave[fastapi,tasks]
```

## Usage

### Chalice Example

You can then create a REST API blueprint as follows:
```python
from agave.chalice import RestApiBlueprint

app = RestApiBlueprint()

@app.resource('/accounts')
class Account:
    model = AccountModel
    query_validator = AccountQuery
    update_validator = AccountUpdateRequest
    get_query_filter = generic_query

    @staticmethod
    @app.validate(AccountRequest)
    def create(request: AccountRequest) -> Response:
        account = AccountModel(
            name=request.name,
            user_id=app.current_user_id,
            platform_id=app.current_platform_id,
        )
        account.save()
        return Response(account.to_dict(), status_code=201)

    @staticmethod
    def update(
        account: AccountModel, request: AccountUpdateRequest
    ) -> Response:
        account.name = request.name
        account.save()
        return Response(account.to_dict(), status_code=200)

    @staticmethod
    def delete(account: AccountModel) -> Response:
        account.deactivated_at = dt.datetime.utcnow().replace(microsecond=0)
        account.save()
        return Response(account.to_dict(), status_code=200)
```

### FastAPI Example

```python
from agave.fastapi import RestApiBlueprint

app = RestApiBlueprint()

@app.resource('/accounts')
class Account:
    model = AccountModel
    query_validator = AccountQuery
    update_validator = AccountUpdateRequest
    get_query_filter = generic_query
    response_model = AccountResponse

    @staticmethod
    async def create(request: AccountRequest) -> Response:
        """This is the description for openapi"""
        account = AccountModel(
            name=request.name,
            user_id=app.current_user_id,
            platform_id=app.current_platform_id,
        )
        await account.async_save()
        return Response(content=account.to_dict(), status_code=201)

    @staticmethod
    async def update(
        account: AccountModel,
        request: AccountUpdateRequest,
    ) -> Response:
        account.name = request.name
        await account.async_save()
        return Response(content=account.to_dict(), status_code=200)

    @staticmethod
    async def delete(account: AccountModel, _: Request) -> Response:
        account.deactivated_at = dt.datetime.utcnow().replace(microsecond=0)
        await account.async_save()
        return Response(content=account.to_dict(), status_code=200)
```

### Async Tasks

```python
from agave.tasks.sqs_tasks import task

QUEUE_URL = 'https://sqs.region.amazonaws.com/account/queue'
AWS_DEFAULT_REGION = 'us-east-1'
@task(
    queue_url=QUEUE_URL,
    region_name=AWS_DEFAULT_REGION,
    visibility_timeout=30,
    max_retries=10,
)
async def process_data(data: dict):
    # Async task processing
    return {'processed': data}
```

## Running Tests

Run the tests using the following command:

```bash
make test
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/cuenca-mx/agave",
    "name": "agave",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Cuenca",
    "author_email": "dev@cuenca.com",
    "download_url": "https://files.pythonhosted.org/packages/c1/3d/5c81dfe06213aece6244c604b58d0b2ce2c36139f495e22ebc79cb99fda2/agave-1.4.0.tar.gz",
    "platform": null,
    "description": "# agave\n[![test](https://github.com/cuenca-mx/agave/workflows/test/badge.svg)](https://github.com/cuenca-mx/agave/actions?query=workflow%3Atest)\n[![codecov](https://codecov.io/gh/cuenca-mx/agave/branch/main/graph/badge.svg)](https://codecov.io/gh/cuenca-mx/agave)\n[![PyPI](https://img.shields.io/pypi/v/agave.svg)](https://pypi.org/project/agave/)\n\nAgave is a library for building REST APIs using a Blueprint pattern, with support for both AWS Chalice and FastAPI frameworks. It simplifies the creation of JSON-based endpoints for querying, modifying, and creating resources.\n\n## Installation\n\nChoose the installation option based on your framework:\n\n### Chalice Installation\n\n```bash\npip install agave[chalice]\n```\n\n### FastAPI Installation\n\n```bash\npip install agave[fastapi]\n```\n\n### SQS task support:\n```bash\npip install agave[fastapi,tasks]\n```\n\n## Usage\n\n### Chalice Example\n\nYou can then create a REST API blueprint as follows:\n```python\nfrom agave.chalice import RestApiBlueprint\n\napp = RestApiBlueprint()\n\n@app.resource('/accounts')\nclass Account:\n    model = AccountModel\n    query_validator = AccountQuery\n    update_validator = AccountUpdateRequest\n    get_query_filter = generic_query\n\n    @staticmethod\n    @app.validate(AccountRequest)\n    def create(request: AccountRequest) -> Response:\n        account = AccountModel(\n            name=request.name,\n            user_id=app.current_user_id,\n            platform_id=app.current_platform_id,\n        )\n        account.save()\n        return Response(account.to_dict(), status_code=201)\n\n    @staticmethod\n    def update(\n        account: AccountModel, request: AccountUpdateRequest\n    ) -> Response:\n        account.name = request.name\n        account.save()\n        return Response(account.to_dict(), status_code=200)\n\n    @staticmethod\n    def delete(account: AccountModel) -> Response:\n        account.deactivated_at = dt.datetime.utcnow().replace(microsecond=0)\n        account.save()\n        return Response(account.to_dict(), status_code=200)\n```\n\n### FastAPI Example\n\n```python\nfrom agave.fastapi import RestApiBlueprint\n\napp = RestApiBlueprint()\n\n@app.resource('/accounts')\nclass Account:\n    model = AccountModel\n    query_validator = AccountQuery\n    update_validator = AccountUpdateRequest\n    get_query_filter = generic_query\n    response_model = AccountResponse\n\n    @staticmethod\n    async def create(request: AccountRequest) -> Response:\n        \"\"\"This is the description for openapi\"\"\"\n        account = AccountModel(\n            name=request.name,\n            user_id=app.current_user_id,\n            platform_id=app.current_platform_id,\n        )\n        await account.async_save()\n        return Response(content=account.to_dict(), status_code=201)\n\n    @staticmethod\n    async def update(\n        account: AccountModel,\n        request: AccountUpdateRequest,\n    ) -> Response:\n        account.name = request.name\n        await account.async_save()\n        return Response(content=account.to_dict(), status_code=200)\n\n    @staticmethod\n    async def delete(account: AccountModel, _: Request) -> Response:\n        account.deactivated_at = dt.datetime.utcnow().replace(microsecond=0)\n        await account.async_save()\n        return Response(content=account.to_dict(), status_code=200)\n```\n\n### Async Tasks\n\n```python\nfrom agave.tasks.sqs_tasks import task\n\nQUEUE_URL = 'https://sqs.region.amazonaws.com/account/queue'\nAWS_DEFAULT_REGION = 'us-east-1'\n@task(\n    queue_url=QUEUE_URL,\n    region_name=AWS_DEFAULT_REGION,\n    visibility_timeout=30,\n    max_retries=10,\n)\nasync def process_data(data: dict):\n    # Async task processing\n    return {'processed': data}\n```\n\n## Running Tests\n\nRun the tests using the following command:\n\n```bash\nmake test\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Rest_api",
    "version": "1.4.0",
    "project_urls": {
        "Homepage": "https://github.com/cuenca-mx/agave"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "c13d5c81dfe06213aece6244c604b58d0b2ce2c36139f495e22ebc79cb99fda2",
                "md5": "0b89355445ebeb768395dbcd31479665",
                "sha256": "367eb20483e2729b11d400cfb28e97d19b195fead84314f30c9fccea63c8b1fd"
            },
            "downloads": -1,
            "filename": "agave-1.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0b89355445ebeb768395dbcd31479665",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 33168,
            "upload_time": "2025-04-09T01:26:38",
            "upload_time_iso_8601": "2025-04-09T01:26:38.587865Z",
            "url": "https://files.pythonhosted.org/packages/c1/3d/5c81dfe06213aece6244c604b58d0b2ce2c36139f495e22ebc79cb99fda2/agave-1.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-04-09 01:26:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cuenca-mx",
    "github_project": "agave",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "boto3",
            "specs": [
                [
                    "==",
                    "1.35.74"
                ]
            ]
        },
        {
            "name": "types-boto3",
            "specs": [
                [
                    "==",
                    "1.35.74"
                ]
            ]
        },
        {
            "name": "cuenca-validations",
            "specs": [
                [
                    "==",
                    "2.1.3"
                ]
            ]
        },
        {
            "name": "chalice",
            "specs": [
                [
                    "==",
                    "1.31.3"
                ]
            ]
        },
        {
            "name": "mongoengine",
            "specs": [
                [
                    "==",
                    "0.29.1"
                ]
            ]
        },
        {
            "name": "fastapi",
            "specs": [
                [
                    "==",
                    "0.115.11"
                ]
            ]
        },
        {
            "name": "mongoengine-plus",
            "specs": [
                [
                    "==",
                    "1.0.0"
                ]
            ]
        },
        {
            "name": "python-multipart",
            "specs": [
                [
                    "==",
                    "0.0.20"
                ]
            ]
        },
        {
            "name": "pydantic",
            "specs": [
                [
                    "==",
                    "2.10.6"
                ]
            ]
        },
        {
            "name": "starlette",
            "specs": [
                [
                    "==",
                    "0.45.3"
                ]
            ]
        },
        {
            "name": "starlette-context",
            "specs": [
                [
                    "==",
                    "0.3.6"
                ]
            ]
        },
        {
            "name": "aiobotocore",
            "specs": [
                [
                    "==",
                    "2.17.0"
                ]
            ]
        },
        {
            "name": "types-aiobotocore-sqs",
            "specs": [
                [
                    "==",
                    "2.17.0"
                ]
            ]
        }
    ],
    "lcname": "agave"
}
        
Elapsed time: 0.40791s