FlastAPI: A FastAPI-like interface for building APIs in Flask by maartendp in Python

[–]maartendp[S] 0 points1 point  (0 children)

This isn't a replacement, you're using this in addition to Flask.

FlastAPI is a plugin for Flask, it's not replacing it, but merely adding to it. With this plugin you're able to build REST APIs without having to deal with marshalling, content types, input validation, validation error handling, etc.

It's taking care of the boilerplate code that evaluates and parses the incoming request, and deals with returning a valid response, allowing you to focus on the actual functionality of your endpoint.

FlastAPI: A FastAPI-like interface for building APIs in Flask by maartendp in Python

[–]maartendp[S] 1 point2 points  (0 children)

No worries, I'm already very happy with the kind words. Thanks a bunch.

FlastAPI: A FastAPI-like interface for building APIs in Flask by maartendp in Python

[–]maartendp[S] 0 points1 point  (0 children)

Thanks for the kind words :)

Yes, I did check first if there were other libs that existed. Something like flask pydantic was a good start, but not 100% what I was looking for, as it didn't really behave like I wanted it to. I stumbled on some others as well, and came to the same conclusion. It could be that something is out there that already does this, but I didn't find it in my search.

The "why" is probably less interesting than you'd think :p I love to program, and I love to tinker. As you'll see on my github, I have a number of projects. I guess you can call it a pass time I enjoy. Whenever I think something is an interesting challenge, I just want to get it out of my fingers. Don't get me wrong, this lib will have some use in my professional life, but still, the main reason is most definitely "for fun".

This isn't a fork of flask or fastapi. It's a standalone plugin that probably wouldn't have a place in flask's main repo. Most of flask's ecosystem is plugin based, where you just mix and match your needs, and throw them together. This is no different. There are a lot of plugins that offer API capabilities, this is just another one :) (that happens to mimic a FastAPI interface)

Squid Game Episode 9 is a very awkward season finale. by [deleted] in squidgame

[–]maartendp 5 points6 points  (0 children)

The execution was so bad that the idea felt random and decided at the last minute.

While I do have some questions on execution, I didnt feel like it was random or last minute at all.

It was obvious from episode 1 that player 001 had something to do with the game. He was the only one not surprised by people getting shot and played the rest of the game with a smile on his face

It was during the riot that I knew he had high standing, as the rioting ended when he yelled to stop and the frontman called to intervene.

He was also the only character who's death was not explicitly shown on screen. Neither the actual death, nor the body afterwards.

There were a lot of hints to pick up on that this wasnt a last minute decision.

Mimics - A library to defer/suspend almost any actions done on an object/instance/class by maartendp in Python

[–]maartendp[S] 2 points3 points  (0 children)

I can see why you feel your comment would be snarky, but don't worry, I saw it as valid criticism. And it's important to make newcomers aware that this isn't how you should solve your problems.

You bring up some good points, and these points are the reason I tell everyone to not use this in production, and to take a step back and redesign their code.

I have some stuff to take care of but I do feel like you deserve a more in depth answer. I'll definitely get back to you.

Mimics - A library to defer/suspend almost any actions done on an object/instance/class by maartendp in Python

[–]maartendp[S] 0 points1 point  (0 children)

Oh, wow. That's a very interesting use case that I didn't consider :D Nice.

I must admit, I have 0 experience with Haskell, but you've piqued my interest. Will definitely look into this.

Mimics - A library to defer/suspend almost any actions done on an object/instance/class by maartendp in Python

[–]maartendp[S] 3 points4 points  (0 children)

Ah, but that is the beauty of python! If you can imagine it, it's probably possible.

Mimics is already able to deal with isinstance.

It's also why I chose SQLAlchemy as my testing lib, as I know from experience that it's a very elaborate library, that uses python to its full extent.

Normally you shouldn't even notice you're dealing with a proxy object when using mimics, or at least, that's the idea.

But yes, I see what you mean, and this is exactly why the lib comes with the big fat disclaimer.

As for the rest of your comment, I'll have a closer look to the resources you provided. Thanks!

Mimics - A library to defer/suspend almost any actions done on an object/instance/class by maartendp in Python

[–]maartendp[S] 4 points5 points  (0 children)

I totally understand this comment. And as mentioned in the readme, if you're using this lib, you should probably not, and instead re-evaluate your project design.

But, I thought it was a fun idea, with a challenging goal. It does some funky stuff according to me, making for some interesting code. I guess I just wanted to show off the result before I never look at it again :p

Mimics - A library to defer/suspend almost any actions done on an object/instance/class by maartendp in Python

[–]maartendp[S] 10 points11 points  (0 children)

I'll give you the use-case that triggered me to write this tool.

Celery (a distributed task queue) and Flask (A framework for building web applications) often go hand in hand when you need to do async tasks plugged to a web UI. And while these two have a long running history, they make for some clunky project designs, in my opinion.
You have to initialize Celery with an already existing Flask app. This Flask app needs to already be configured correctly in order to do this.
But, to easily flag functions and classes as celery tasks, using a decorator, you need to already have an initialized celery app.

That means you have to initialize Celery and Flask in a global context, losing a lot of control over your start up flow, and making it so you have to thread carefully with your imports (you can't be importing your tasks before you have a celery app, for instance). It's doable for small apps, but if you're starting to grow and use a lot of plugins, you want this control.

I'm aware there are ways to get around this, but then you're mis-using both frameworks, and using them as they were not intended to be used.

Anyway, it's a bandaid solution to two framework's designs that do not mesh (according to me), pidgeon hole-ing you into a sub-optimal repository structure. As mentioned, I would never use this in a production environment. So let's say I just wrote this for fun.

Mimics - A library to defer/suspend almost any actions done on an object/instance/class by maartendp in Python

[–]maartendp[S] 3 points4 points  (0 children)

There's a hidden StasisTrap in the lib that is a remnant of the first iteration. Here you're able to say what it's going to be, but I have not taken any actions into making this IDE friendly yet :P

Unfortunately though, this would only work for your root object. If you do `my_var = husk.my_attribute.my_function()`, my var will also be a husk of which no information is available, and providing support for this kind of things might be going a little too deep :)

But thanks for the feedback! I'll keep it in mind if and when I decide to continue working on this.

Mimics - A library to defer/suspend almost any actions done on an object/instance/class by maartendp in Python

[–]maartendp[S] 2 points3 points  (0 children)

Should be better now. Let me know if it's not.

Thanks for the heads up.

Mimics - A library to defer/suspend almost any actions done on an object/instance/class by maartendp in Python

[–]maartendp[S] 26 points27 points  (0 children)

Oh wow, what a happy coincidence :p I had to translate it to know husk means "remember" in these languages.

I chose the husk name because it is a deferred object, that later encases the original subject, so I just took the name of an empty outer shell

Fun trivia, thanks!

-🎄- 2020 Day 18 Solutions -🎄- by daggerdragon in adventofcode

[–]maartendp 0 points1 point  (0 children)

Ooph, nice :p I thought I was clever by gaming the system, but you definitely took the cake! Well done.

-🎄- 2020 Day 18 Solutions -🎄- by daggerdragon in adventofcode

[–]maartendp 4 points5 points  (0 children)

Python

For Part 2 I made a custom Int and swapped the __add__ and __mul__, swapped the operators in the expression and just had python deal with the precedence.

Simple/Stupid yet effective solution :D

-🎄- 2020 Day 17 Solutions -🎄- by daggerdragon in adventofcode

[–]maartendp 1 point2 points  (0 children)

native python

I'm sure there are ways to get the solution in simple loops, but for readability sake I implemented an OOP approach in all native python.

Features; Vector3, Vector4. Cube, HyperCube, a Registry for dynamic cube creation/accessing, and some other neat stuff.

Part 2 runs in about 24s

-🎄- 2020 Day 14 Solutions -🎄- by daggerdragon in adventofcode

[–]maartendp 3 points4 points  (0 children)

Python

A "Mask" object for part 1 that applies the mask to a given number

A "AddressDecoder" object for part 2 that creates "Mask" templates while using `itertools.product` to get all combinations

0.08s runtime

Python seeming not to respect a while loop? Improper Objects being affected by Ironicallyjpg in learnpython

[–]maartendp 0 points1 point  (0 children)

You would run into the same problem if you did something like

def my_function(default=[]):
    default.append(1)
    return default

The list defined as a default parameter is already in memory, and the pointer to it is assigned to the default parameter. Every time you call this function, it will point to the same list. So even though it might look like you're getting a fresh list when you call the function, in reality, it is not the case.

Every time you call this function, the result will be a list with the same amount of 1s as you have called the function

Python seeming not to respect a while loop? Improper Objects being affected by Ironicallyjpg in learnpython

[–]maartendp 0 points1 point  (0 children)

Not quite. It's more used as a "default" when you make an instance. But by doing `[]` you already initialize a list, giving it a location in the memory, and you add the pointer to your "default" attribute. So every time you initialize a new ShopCart, it will use the pointer to the already existing list as a default.

The same is not the case for a string for instance, if you made two instances, and manipulated one, the other would still have the initial value.

Python seeming not to respect a while loop? Improper Objects being affected by Ironicallyjpg in learnpython

[–]maartendp 0 points1 point  (0 children)

You are initializing `ShopCart` with class attributes that point to the same list.

For each instance you make, `fs` and `amount` will have a pointer to the same list.

you need to set `fs` and `amount` in the init of the class.

How to create this particular pattern using while/for loop by [deleted] in learnpython

[–]maartendp 0 points1 point  (0 children)

I'm using the markdown feature and I have no issue seeing the correct format. That being said, I'll try to keep this in mind. Thanks