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
Requirements
- Python 3.6+
Installation
Use the package manager pip to install py flask micro service core .
pip install zpy-api-core
Features
Contains some helper features.
- Api
- Api Builder
- Response Builder
- Models
- Hooks
- Middlewares
- Exceptions
- Cloud Implementations
- Aws Handler decorators
- See: AWS Package
- 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
- Collections
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
awesome-api
│ .env
│ .gitignore
│ CHANGELOG.md
│ CHANGELOG.md
│ README.md
│ requirements.txt
│
└───src
│ │ di.py
│ │ handler.py
│ │ local_deploy.py
│ │
│ └───┬api
│ │ routes.py
│ │ ...
│ └contexts
│ │ ...
│ └───users
│ │ ...
│ └───┬application
│ │ │ ...
│ └───┬domain
│ │ │ ...
│ └───┬infraestructure
│ │ ...
└───tests
│ user_searcher_test.py
Dependencies file
# 🛸 Generated by zPy
from zpy.utils import get_env_or_throw as var
from zpy.app.usecase 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...")
routes.py
# 🛸 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"])
@response_builder
def users():
return user_searcher_uc.execute(None)
Use Case
# 🛸 Generated by zPy
from typing import Any
from zpy.app.usecase 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
load_dotenv(
dotenv_path="|3:\\projects\\demos\\awesome-api\\.env"
)
from api.routes import app
if __name__ == "__main__":
app.run(host="127.0.0.1", port=5050, debug=True)
handler.py configure for aws lambda and api gateway
# 🛸 Generated by zPy
from zpy.api.cloud_handlers import aws_lambda
from api.routes import app
import aws_lambda_wsgi as awsgi
@aws_lambda()
def handle(event: dict, context: dict) -> any:
return awsgi.response(app, event, context)
Contributing
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.
License
Authors
Metadata
Release files for zpy-api-core 2.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| zpy_api_core-2.3.0.tar.gz | 54.9 kB | Without provenance | Details for zpy_api_core-2.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| zpy_api_core-2.3.0-py3-none-any.whl | Python 3 | none | any | Details for zpy_api_core-2.3.0-py3-none-any.whl |
Total release size: 122.8 kB
Release files / zpy_api_core-2.3.0.tar.gz
| Download URL | zpy_api_core-2.3.0.tar.gz |
|---|---|
| Size | 54.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
24bd06be2bfcc4749705580b31f579cceb31a4e8070de172b377ea2734dc41f3
|
|
BLAKE2b-256 checksum How to use checksums |
9a748f35a9736e033a837ceee143fef247733a769fd7c33fb95bedf8a18ab717
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.3
|
Release files / zpy_api_core-2.3.0-py3-none-any.whl
| Download URL | zpy_api_core-2.3.0-py3-none-any.whl |
|---|---|
| Size | 67.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4663f313667e4b656a482b08fdc1ef1fb1b2b38092c81c07b3988144df40bb16
|
|
BLAKE2b-256 checksum How to use checksums |
ac2d529eba113333124d2367e1d947e8cf0b2e95c682b54ec909768110d34b92
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.3
|
Security for zpy-api-core 2.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.