Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

agave

test codecov PyPI

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

pip install agave[chalice]

FastAPI Installation

pip install agave[fastapi]

SQS task support:

pip install agave[fastapi,tasks]

Usage

Chalice Example

You can then create a REST API blueprint as follows:

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

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

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:

make test

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agave-1.2.0.dev100.tar.gz (30.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agave-1.2.0.dev100-py3-none-any.whl (40.2 kB view details)

Uploaded Python 3

File details

Details for the file agave-1.2.0.dev100.tar.gz.

File metadata

  • Download URL: agave-1.2.0.dev100.tar.gz
  • Upload date:
  • Size: 30.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for agave-1.2.0.dev100.tar.gz
Algorithm Hash digest
SHA256 e5d33f8479ce3bb6d6a28972f4dd3fd03cb9bcf09aa89ae454ad0806a689d6c8
MD5 657cfdc3b159a39bf04db75537db1bec
BLAKE2b-256 c31e60ff7c10db2a261212294e99fabf89b415e3da0dbe8318c7301e5064be4d

See more details on using hashes here.

File details

Details for the file agave-1.2.0.dev100-py3-none-any.whl.

File metadata

  • Download URL: agave-1.2.0.dev100-py3-none-any.whl
  • Upload date:
  • Size: 40.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for agave-1.2.0.dev100-py3-none-any.whl
Algorithm Hash digest
SHA256 765077f103eaad40562fee25025a97f55c481a434502e51403f790278f8c25ab
MD5 33494d5fdc1848d01be49de68fcbbe6b
BLAKE2b-256 772506788af5c13b30991cab570df5e87bd3baf180093950c852ef1d85603f14

See more details on using hashes here.

Release history Release notifications | RSS feed

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page