Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (10.2%) to scientific vocabulary
Keywords from Contributors
Repository
Basic Info
- Host: GitHub
- Owner: cuenca-mx
- License: mit
- Language: Python
- Default Branch: main
- Size: 441 KB
Statistics
- Stars: 7
- Watchers: 6
- Forks: 1
- Open Issues: 25
- Releases: 80
Metadata Files
README.md
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 (only FastApi based app):
bash
pip install agave[fastapi,tasks]
Models
AsyncDocument for FastAPI
When using FastAPI, models should inherit from mongoengine_plus.aio.AsyncDocument to enable async MongoDB operations:
```python from mongoengine import StringField, DateTimeField from mongoengineplus.aio import AsyncDocument from mongoengineplus.models import BaseModel
class Account(BaseModel, AsyncDocument): name = StringField(required=True) user_id = StringField(required=True) # ...other fields
# Use async methods:
# await account.async_save()
# await Account.objects.async_get(id=id)
# await Account.objects.filter(...).async_to_list()
```
Document for Chalice
For Chalice, use standard MongoEngine Document:
```python from mongoengine import Document, StringField, DateTimeField
class Account(Document): name = StringField(required=True) user_id = StringField(required=True) # ...other fields
# Use sync methods:
# account.save()
# Account.objects.get(id=id)
```
Usage
Chalice Example
Create a REST API blueprint as follows: ```python import datetime as dt from chalice import Response from agave.chalice import RestApiBlueprint
app = RestApiBlueprint()
The @app.resource decorator automatically creates these endpoints:
- GET /accounts => Query with filters
- GET /accounts/{id} => Get account by ID
Additional endpoints are created only if you define the corresponding methods:
- POST /accounts => created if 'create' method is defined
- PATCH /accounts/{id} => created if 'update' method is defined
- DELETE /accounts/{id} => created if 'delete' method is defined
@app.resource('/accounts') class Account: model = AccountModel queryvalidator = AccountQuery updatevalidator = AccountUpdateRequest getqueryfilter = generic_query
# Optional: Define create method to enable POST endpoint
@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)
# Optional: Define update method to enable PATCH endpoint
@staticmethod
def update(
account: AccountModel, request: AccountUpdateRequest
) -> Response:
account.name = request.name
account.save()
return Response(account.to_dict(), status_code=200)
# Optional: Define delete method to enable DELETE endpoint
@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 import datetime as dt from fastapi import Request from fastapi.responses import JSONResponse as Response from agave.fastapi import RestApiBlueprint
app = RestApiBlueprint()
The @app.resource decorator automatically creates these endpoints:
- GET /accounts => Query with filters
- GET /accounts/{id} => Get account by ID
Additional endpoints are created only if you define the corresponding methods:
- POST /accounts => created if 'create' method is defined
- PATCH /accounts/{id} => created if 'update' method is defined
- DELETE /accounts/{id} => created if 'delete' method is defined
@app.resource('/accounts') class Account: model = AccountModel # AsyncDocument model queryvalidator = AccountQuery updatevalidator = AccountUpdateRequest getqueryfilter = genericquery responsemodel = AccountResponse # FastAPI specific
# Optional: Define create method to enable POST endpoint
@staticmethod
async def create(request: AccountRequest) -> Response:
"""This is the description for OpenAPI documentation"""
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)
# Optional: Define update method to enable PATCH endpoint
@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)
# Optional: Define delete method to enable DELETE endpoint
@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
Agave's SQS tasks support Pydantic model validation. When you send a JSON message to an SQS queue, the task will automatically parse and convert it to the specified Pydantic model:
```python from pydantic import BaseModel from agave.tasks.sqs_tasks import task
Define Pydantic model for request validation
class UserData(BaseModel): name: str age: int email: str
QUEUEURL = 'https://sqs.region.amazonaws.com/account/queue' AWSDEFAULT_REGION = 'us-east-1'
Task with Pydantic model type hint
@task( queueurl=QUEUEURL, regionname=AWSDEFAULTREGION, visibilitytimeout=30, maxretries=10, ) async def processuser(user: UserData): # user is already a validated UserData instance, not a dict print(f"Processing user {user.name} with email {user.email}") # Your processing logic here return {"success": True, "user_name": user.name} ```
Use RetryTask exception to implement retry logic:
```python from agave.core.exc import RetryTask from agave.tasks.sqs_tasks import task
@task(queueurl=QUEUEURL, regionname=AWSDEFAULTREGION, maxretries=3) async def processwithretry(data: dict): try: # Your processing logic result = await some_operation(data) except TemporaryError: # Will retry automatically raise RetryTask
return result
```
Running Tests
Run the tests using the following command:
bash
make test
Owner
- Name: Cuenca
- Login: cuenca-mx
- Kind: organization
- Location: CDMX
- Website: https://cuenca.com
- Repositories: 52
- Profile: https://github.com/cuenca-mx
La única cuenta que necesitas en México
GitHub Events
Total
- Create event: 59
- Issues event: 8
- Release event: 42
- Watch event: 3
- Delete event: 11
- Issue comment event: 33
- Push event: 100
- Pull request review event: 157
- Pull request review comment event: 156
- Pull request event: 28
Last Year
- Create event: 59
- Issues event: 8
- Release event: 42
- Watch event: 3
- Delete event: 11
- Issue comment event: 33
- Push event: 100
- Pull request review event: 157
- Pull request review comment event: 156
- Pull request event: 28
Committers
Last synced: over 2 years ago
Top Committers
| Name | Commits | |
|---|---|---|
| dependabot[bot] | 4****] | 28 |
| Felipe López | 3****o | 5 |
| Ricardo | r****c@c****m | 3 |
| Keryc Diaz | k****c@c****m | 3 |
| Rogelio | r****4@g****m | 2 |
| Matin Tamizi | m****n | 2 |
| Gleekzone | 4****e | 1 |
| Yisus | a****n@c****m | 1 |
| Alex Viquez | a****2@g****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 21
- Total pull requests: 122
- Average time to close issues: 25 days
- Average time to close pull requests: about 1 month
- Total issue authors: 8
- Total pull request authors: 10
- Average comments per issue: 0.19
- Average comments per pull request: 1.76
- Merged pull requests: 38
- Bot issues: 7
- Bot pull requests: 78
Past Year
- Issues: 12
- Pull requests: 30
- Average time to close issues: N/A
- Average time to close pull requests: 8 days
- Issue authors: 3
- Pull request authors: 2
- Average comments per issue: 0.25
- Average comments per pull request: 1.8
- Merged pull requests: 19
- Bot issues: 7
- Bot pull requests: 0
Top Authors
Issue Authors
- coderabbitai[bot] (7)
- gmorales96 (3)
- keryc (2)
- felipaoo (2)
- rogelioLpz (2)
- ricardo8990 (2)
- felipao-mx (2)
- agarrido19 (1)
Pull Request Authors
- dependabot[bot] (78)
- gmorales96 (18)
- felipao-mx (14)
- keryc (3)
- ricardo8990 (2)
- felipaoo (2)
- rogelioLpz (2)
- agarrido19 (2)
- chiqeen03 (1)
- matin (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 1,785 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 110
- Total maintainers: 2
pypi.org: agave
Rest_api
- Homepage: https://github.com/cuenca-mx/agave
- Documentation: https://agave.readthedocs.io/
- License: MIT License
-
Latest release: 1.4.1
published 6 months ago
Rankings
Dependencies
- black ==20.8b1 test
- click ==8.0.1 test
- flake8 ==3.8. test
- isort ==5.7. test
- mock ==4.0.3 test
- mongomock ==3.22. test
- mypy ==0.812 test
- pytest ==6.2. test
- pytest-chalice ==0.0. test
- pytest-cov ==2.11. test
- pytest-freezegun ==0.4. test
- blinker ==1.4
- chalice ==1.25.0
- cuenca-validations ==0.10.0
- dnspython ==2.1.0
- mongoengine ==0.22.1
- blinker >=1.4,<1.5
- chalice >=1.16.0,<1.25.1
- cuenca-validations >=0.9.0,<1.0.0
- dnspython >=2.0.0,<2.2.0
- mongoengine >=0.20.0,<0.23.0
- actions/checkout master composite
- actions/setup-python v2.2.1 composite
- pypa/gh-action-pypi-publish master composite
- actions/checkout v2 composite
- actions/checkout master composite
- actions/setup-python v2.2.1 composite
- codecov/codecov-action v1 composite