Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Flask example project. #40

Closed
M0dM opened this issue Jul 9, 2019 · 15 comments
Closed

Flask example project. #40

M0dM opened this issue Jul 9, 2019 · 15 comments

Comments

@M0dM
Copy link

M0dM commented Jul 9, 2019

Hi,

I would love to have a flask example project like the one you've done for django.

M0dM

@proofit404
Copy link
Contributor

Hi, thank you for your interest in the dry-python project!

We will eventually provide tutorials for flask, aiohttp and pyramid projects.

Flask tutorial is blocked by these issues:
https://github.com/dry-python/mappers/issues/1
proofit404/dependencies#65
proofit404/dependencies#90

Because at this point we have limited Flask support in our integrations, we won't include it to the tutorial right now.

At this point you can use Flask this way:

  1. All Flask views are one-liners. They should take arguments from the HTTP request and call a story method. When the story method returns something, they should build an HTTP response from it.
  2. You can build the story method using dependencies as usual.
  3. You can pass SQLAlchemy models and tables using DI to the story method constructor.

If you have any questions, feel free to ask them in our Gitter or here!

Have a good day 🎉

Best regards,
Artem.

@M0dM
Copy link
Author

M0dM commented Jul 10, 2019

Hi @proofit404 ,

Thanks for the quick response.

We are starting a new project using dry-python (stories, dependencies and attrs) with flask but django ORM (like in this gist: https://gist.github.com/seanbehan/168a277a5a23086e76000a59e54fb3d5).

We made the choice to use django ORM as we already have related project written in django and all the team is familliar with it.
We want to use flask for more flexibility for this new product.

We do not understand yet all the benefits of using dependencies and attrs but stories seems very promising for us.

This is a very new projet so the structure is not very fixed yet.
We are making a POC right now.
Do you think, using django ORM instead of Sql alchemy would make it easier for us ?

Regards,
Benoit

@proofit404
Copy link
Contributor

proofit404 commented Jul 11, 2019

I guess it's very reasonable to use Django ORM in your conditions. I also prefer Django migrations over alembic.

It's easy to use any routing/view layer together with dry-python because it doesn't know anything about database under the hood.

Everything view layer knows about is stories the service layer.

You will appreciate the power of the dependencies if you decide to write your stories decoupled from the actual implementations.

For example, let's take a look at this step implementation: https://github.com/dry-python/tutorials/blob/1c2b9547ccf60551a42c2e7160cbaab8960f4144/django/example/services/buy_subscription.py#L60-L65

The actual business logic here "notify the user at the end of this scenario" does not know how you're going to do it.

Maybe it will Twilio SMS gateway, maybe it will be Django Channels WebSocket, maybe it will be Google cloud messaging push notification to the user smartphone.

Business logic doesn't care about this.

When we would see it? In an actual use case of this story.

https://github.com/dry-python/tutorials/blob/1c2b9547ccf60551a42c2e7160cbaab8960f4144/django/example/views/buy_subscription.py#L38

https://github.com/dry-python/tutorials/blob/1c2b9547ccf60551a42c2e7160cbaab8960f4144/django/example/implemented.py#L29

This way you view layer decide in what way this actual view can notify the user. You can even have many configurations at different API endpoints using the same story object.

POST /api/subscriptions/buy?notify=ws
POST /api/subscriptions/buy?notify=push
POST /api/subscriptions/buy?notify=sms

Btw, we have a pro support plan for the whole family of dry-python libraries. So if you met urgent bug, lack some critical feature or need on-premise training don't hesitate to contact us at https://drylabs.io/

P.S. Since you're using Django maybe you'll be interested in the mappers project as well.

Best regards,
Artem.

@M0dM
Copy link
Author

M0dM commented Jul 11, 2019

I think we are now ready to test it in depth.
Unfortunately I am not sure I would be allowed to produce a flask tutorial with django ORM but I will try to discuss it with my boss.

Anyway, thanks a lot for your time.

Benoit

@M0dM
Copy link
Author

M0dM commented Jul 19, 2019

Hi Artem,

We will produce a tutorial project including dependencies and stories with connexion (https://github.com/zalando/connexion) and django ORM for a presentation we might give in september.

If you want it could be a good start for a flask tutorial with django ORM.
I will let you know as soon as this project is on github.

Regards,
Benoit

@proofit404
Copy link
Contributor

Hi Benoit,

It would be awesome! 100% awesome! And it is 100% welcome!

It would be helpful if it'll be not one huge pull request, but a series of small sequential pull requests. And we can start this iteration as soon as possible.

By the way, what kind of presentation you suppose to give in September? How could I help?

Regards, Artem.

@M0dM
Copy link
Author

M0dM commented Jul 19, 2019

As this is code we produced durring our working hours with my colleague, we will add it in a separate repository in a new organisation we will create for the occasion.

But, as the code should be released with MIT or BSD license we should be able to use it to build a dry-python example project from it.

I will try to help in my spare time to do this.

The presentation is about code quality and best practices to build clean microservices in python.
We will present it in a meetup in September of October in Grenoble (in the French Alpes).

@proofit404
Copy link
Contributor

@M0dM Could you provide some link for Grenoble Python Meetup in September? We would like to share it in dry-python tweeter and site.

@M0dM
Copy link
Author

M0dM commented Aug 6, 2019 via email

@M0dM
Copy link
Author

M0dM commented Sep 3, 2019

Hi @proofit404,

The date is set for the 12 of December finally.

I will let you know as soon as I have some material.

@proofit404
Copy link
Contributor

Cool! Thanks for the update.

@M0dM
Copy link
Author

M0dM commented Dec 13, 2019

Hi @proofit404,

We did it.
https://github.com/Alma-CFAO/PyApiFirstDemo

Django ORM + Connexion (Api first with flask) + stories & dependencies + other tools

@proofit404
Copy link
Contributor

Thank you 🎉 🕺 🎉

https://twitter.com/dry_py/status/1207658468569702400

Let me know if there is a video available for it!

@M0dM
Copy link
Author

M0dM commented Dec 19, 2019

No, we don't have any video.
Thanks for the visibility ;)

@ghost
Copy link

ghost commented Mar 7, 2020

A separate repo with a complete flask project would be an ideal solution. The same is try for aiohttp, pyramid, fastapi, etc.

@ghost ghost closed this as completed Mar 7, 2020
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants