All Projects → ozgurkara → fastapi-pydiator

ozgurkara / fastapi-pydiator

Licence: other
Python clean architecture and usecase implementation with fastapi and pydiator-core

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to fastapi-pydiator

fastapi-boilerplate
FastAPI boilerplate for real world production
Stars: ✭ 145 (+150%)
Mutual labels:  fastapi, fastapi-template, fastapi-boilerplate
fastapi-uvicorn-gunicorn-nginx-supervisor-boilerplate
Production ready boilerplate to start with Fastapi
Stars: ✭ 17 (-70.69%)
Mutual labels:  fastapi, fastapi-template, fastapi-boilerplate
fastapi-mvc
Developer productivity tool for making high-quality FastAPI production-ready APIs.
Stars: ✭ 131 (+125.86%)
Mutual labels:  fastapi, fastapi-template, fastapi-boilerplate
FastAPI Tortoise template
FastAPI - Tortoise ORM - Celery - Docker template
Stars: ✭ 144 (+148.28%)
Mutual labels:  fastapi, fastapi-template, fastapi-boilerplate
Android Modular Architecture
📚 Sample Android Components Architecture on a modular word focused on the scalability, testability and maintainability written in Kotlin, following best practices using Jetpack.
Stars: ✭ 2,048 (+3431.03%)
Mutual labels:  clean-code, clean-architecture, solid-principles
CleanArchitecture-Template
This is a solution template for Clean Architecture and CQRS implementation with ASP.NET Core.
Stars: ✭ 60 (+3.45%)
Mutual labels:  clean-code, clean-architecture, mediatr
fastapi-starter
A FastAPI based low code starter: Async SQLAlchemy, Postgres, React-Admin, pytest and cypress
Stars: ✭ 97 (+67.24%)
Mutual labels:  fastapi, fastapi-template, fastapi-boilerplate
CleanArchitectureMVVM
Example of Clean Architecture of Android app using MVVM, Koin, Coroutines, Retrofit, Room, Solid Principle, DRY, KISS, OOP
Stars: ✭ 60 (+3.45%)
Mutual labels:  clean-code, clean-architecture, solid-principles
Clean Architecture Manga
🌀 Clean Architecture with .NET6, C#10 and React+Redux. Use cases as central organizing structure, completely testable, decoupled from frameworks
Stars: ✭ 3,104 (+5251.72%)
Mutual labels:  clean-code, clean-architecture, solid-principles
FastAPI-template
Feature rich robust FastAPI template.
Stars: ✭ 660 (+1037.93%)
Mutual labels:  fastapi, fastapi-template, fastapi-boilerplate
freddie
DRF-like declarative viewsets for FastAPI
Stars: ✭ 49 (-15.52%)
Mutual labels:  fastapi, fastapi-crud
Android-Clean-Architecture
This is a sample movie list Android application built to demonstrate use of Clean Architecture tools. Dedicated to all Android Developers - (Kotlin, MVVM, Clean Architecture, Rx-Java, Dagger, OkHttp, Unit Testing, SOLID principles, Code Coverage)
Stars: ✭ 268 (+362.07%)
Mutual labels:  clean-architecture, solid-principles
Reddnet
🎭 Minimal Reddit clone
Stars: ✭ 125 (+115.52%)
Mutual labels:  clean-architecture, solid-principles
fastapi-project-template
DO NOT FORK, CLICK "Use this template" - The base to start an openapi project featuring: SQLModel, Typer, FastAPI, JWT Token Auth, Interactive Shell, Management Commands.
Stars: ✭ 262 (+351.72%)
Mutual labels:  python-template, fastapi
go-monolith-example
Example Go monolith with embedded microservices and The Clean Architecture
Stars: ✭ 186 (+220.69%)
Mutual labels:  clean-code, clean-architecture
clean-code-javascript-ko
🛁 Clean Code concepts adapted for JavaScript - 한글 번역판 🇰🇷
Stars: ✭ 1,767 (+2946.55%)
Mutual labels:  clean-code, clean-architecture
flutter clean architecture
A flutter clean architecture series, the way we build clean apps.
Stars: ✭ 225 (+287.93%)
Mutual labels:  clean-code, clean-architecture
Games
The Games app has two features which are listing and showing detail of games.
Stars: ✭ 15 (-74.14%)
Mutual labels:  clean-architecture, solid-principles
eShopOnWeb
Sample ASP.NET Core 6.0 reference application, powered by Microsoft, demonstrating a layered application architecture with monolithic deployment model. Download the eBook PDF from docs folder.
Stars: ✭ 8,250 (+14124.14%)
Mutual labels:  clean-code, clean-architecture
clean architecture typescript example
This repository provides an implementation (or at least an attempt) of Uncle Bob's Clean Architecture with Typescript.
Stars: ✭ 78 (+34.48%)
Mutual labels:  clean-code, clean-architecture

example event parameter Coverage Status

What is the purpose of this repository

This project is an example that how to implement FastAPI and the pydiator-core. You can see the detail of the pydiator-core on this link https://github.com/ozgurkara/pydiator-core

How to run app

uvicorn main:app --reload or docker-compose up

How to run Tests

coverage run --source app/ -m pytest

coverage report -m

coverage html

What is the pydiator?

You can see details here https://github.com/ozgurkara/pydiator-core pydiator

This architecture;

  • Testable
  • Use case oriented
  • Has aspect programming (Authorization, Validation, Cache, Logging, Tracer etc.) support
  • Clean architecture
  • SOLID principles
  • Has publisher subscriber infrastructure

There are ready implementations;

How to add the new use case?

Add New Use Case

#resources/sample/get_sample_by_id.py

class GetSampleByIdRequest(BaseRequest):
    def __init__(self, id: int):
        self.id = id

class GetSampleByIdResponse(BaseResponse):
    def __init__(self, id: int, title: str):
        self.id = id
        self.title = title 

class GetSampleByIdUseCase(BaseHandler):
    async def handle(self, req: GetSampleByIdRequest):
        # related codes are here such as business
        return GetSampleByIdResponse(id=req.id, title="hello pydiatr")    

Register Use Case

# utils/pydiator/pydiator_core_config.py set_up_pydiator 
container.register_request(GetSampleByIdRequest, GetSampleByIdUseCase())

Calling Use Case;

await pydiator.send(GetSampleByIdRequest(id=1))

What is the pipeline?

You can think that the pipeline is middleware for use cases. So, all pipelines are called with the sequence for every use case. You can obtain more features via pipeline such as cache, tracing, log, retry mechanism, authorization. You should know and be careful that if you register a pipeline, it runs for every use case calling.

Add New Pipeline

class SamplePipeline(BasePipeline):
    def __init__(self):
        pass

    async def handle(self, req: BaseRequest) -> object:
        
        # before executed pipeline and use case

        response = await self.next().handle(req)

        # after executed next pipeline and use case            

        return response    

Register Pipeline

# utils/pydiator/pydiator_core_config.py set_up_pydiator 
container.register_pipeline(SamplePipeline())

What is the notification?

The notification feature provides you the pub-sub pattern as ready.

The notification is being used for example in this repository. We want to trigger 2 things if the todo item is added or deleted or updated;

1- We want to clear the to-do list cache.

2- We want to write the id information of the to-do item to console

Add New Notification

class TodoTransactionNotification(BaseModel, BaseNotification):
    id: int = Field(0, gt=0, title="todo id")

Add Subscriber

class TodoClearCacheSubscriber(BaseNotificationHandler):
    def __init__(self):
        self.cache_provider = get_cache_provider()

    async def handle(self, notification: TodoTransactionNotification):
        self.cache_provider.delete(GetTodoAllRequest().get_cache_key())

        
class TransactionLogSubscriber(BaseNotificationHandler):
    def __init__(self):
        self.cache_provider = get_cache_provider()

    async def handle(self, notification: TodoTransactionNotification):
        print(f'the transaction completed. its id {notification.id}')

Register Notification

container.register_notification(TodoTransactionNotification,
                                    [TodoClearCacheSubscriber(), TransactionLogSubscriber()])

Calling Notification

await pydiator.publish(TodoTransactionNotification(id=1))

How to use the cache?

The cache pipeline decides that put to cache or not via the request model. If the request model inherits from the BaseCacheable object, this use case response can be cacheable.
If the cache already exists, the cache pipeline returns with cache data so, the use case is not called. Otherwise, the use case is called and the response of the use case is added to cache on the cache pipeline.

class GetTodoAllRequest(BaseModel, BaseRequest, BaseCacheable):
    # cache key.
    def get_cache_key(self) -> str:
        return type(self).__name__ # it is cache key

    # cache duration value as second
    def get_cache_duration(self) -> int: 
        return 600

    # cache location type
    def get_cache_type(self) -> CacheType:
        return CacheType.DISTRIBUTED

Requirements;

1- Must have a redis and should be set the below environment variables

REDIS_HOST = 'redis ip'

2- Must be activated the below environment variables on the config for using the cache;

DISTRIBUTED_CACHE_IS_ENABLED=True
CACHE_PIPELINE_IS_ENABLED=True

Tracing via Jaeger

Requirements;

1- Must have a jaeger server and should be set the below environment variables

JAEGER_HOST = 'jaeger ip'
JAEGER_PORT = 'jaeger port'

2- Must be activated the below environment variables on the config for using the jaeger;

TRACER_IS_ENABLED=True

pydiator

3- If want to trace the handlers, should be activated the below environment variables on the config for using the jaeger. Otherwise, can just see the endpoint trace details.

CACHE_PIPELINE_IS_ENABLED=True 

pydiator

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].