Skip to main content

Helper layer for apis development with Aws, Python and Flask

Project description


ZPy Core, Layer for build microservices

ZPy Core

Zurck'z Py Flask Micro Services Core

This package contains some helpers features for build python microservices using Flask framework

ZPy use the following packages:

  • Flask
  • marshmallow
  • marshmallow_objects
  • requests
  • aws-lambda-wsgi


  • Python 3.6+


Use the package manager pip to install py flask micro service core .

pip install zpy-api-core


Contains some helper features.

  • Api
    • Api Builder
    • Response Builder
    • Models
    • Hooks
    • Middlewares
    • Exceptions
  • Cloud Implementations
  • CLI
    • DDD Project structure generator
    • Bounded Context Generator
    • UseCases generator
  • Database
  • Logger
    • Stream
  • Utils
    • Collections
      • element finder
    • Dates
      • Time zones
      • Transforms
    • Ciphers
    • Functions
    • Parallel
      • map parallel
      • run parallel
    • Objects
    • gzip

Basic Usage

Generate project using zpy CLI

# Generate project with basic information. for more type: zpy --help
zpy make -p awesome-api -d "My awsome users api" -c Users -uc UserSearcher -op

cd awesome-api

zpy will generate the project with the following structure

│   .env
│   .gitignore
│   requirements.txt    
│   │
│   │
│   │
│   │
│   └───┬api
│       │
│       │   ...
│       └contexts
│       │   ...
│       └───users
│         │   ...
│         └───┬application
│         │   │ ...
│         └───┬domain
│         │   │ ...
│         └───┬infraestructure
│             │ ...

Dependencies file

# 🛸 Generated by zPy
from zpy.utils import get_env_or_throw as var
from import UseCase
from typing import Any

# * Setup Dependencies 📃
from contexts.users.domain.repositories import UserRepository
from contexts.users.infraestructure.payment_repository import AwesomeUserRepository
from contexts.users.application.user_searcher import UserSearcher

repository: UserRepository = AwesomeUserRepository()

# Setup UseCases

user_searcher_uc: UseCase[Any, None] = UserSearcher(repository)
print("🚀 Dependencies loaded successfully...")

# 🛸 Generated by zPy
from di import user_searcher_uc
from flask import Flask
from zpy.api.http.response import response_builder
from zpy.api.flask import create_app

app: Flask = create_app()

@app.route("/api/users", methods=["GET"])
def users():
    return user_searcher_uc.execute(None)

Use Case

# 🛸 Generated by zPy
from typing import Any

from import UseCase

from ..domain.repositories import UserRepository

class UserSearcher(UseCase[Any, Any]):
        Use Case description.

    def __init__(self, repository: PaymentRepository) -> None:
        self.repository = repository

    def execute(self, data: Any, *args, **kwargs) -> None:
        # TODO Do magic with business rules 😁
        return self.repository.user_searcher(data)

Local Dev Deploy

# 🛸 Generated by zPy
from dotenv import load_dotenv


from api.routes import app

if __name__ == "__main__":"", port=5050, debug=True) configure for aws lambda and api gateway

# 🛸 Generated by zPy
from zpy.api.flask.cloud_handlers import aws_lambda

from api.routes import app
import aws_lambda_wsgi as awsgi

def handle(event: dict, context: dict) -> any:
    return awsgi.response(app, event, context)


Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.




Noé Cruz

Project details

Download files

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

Source Distribution

zpy-api-core-1.8.0.tar.gz (53.8 kB view hashes)

Uploaded source

Built Distribution

zpy_api_core-1.8.0-py3-none-any.whl (67.2 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page