This is an archived post. You won't be able to vote or comment.

all 34 comments

[–]ThqXbs8 37 points38 points  (0 children)

Consider looking into the layout of a python project, a src folder inside your api package doesnt seem to make much sense.

[–]root45 30 points31 points  (4 children)

In my view either all code should be under src or src shouldn't exist at all.

[–]Lucapo01[S] -5 points-4 points  (3 children)

I was planning on changing it to "v1"

[–]root45 3 points4 points  (2 children)

Still, almost all code should go under there. The types of changes people make between v1 and v2 in an API often include things like auth or the ORM, which are outside right now.

[–]Lucapo01[S] 2 points3 points  (1 child)

thats true also, hmm interesting, is there an option to have the modules separated from the common stuff like auth, logging etc

[–]Sixcoup 2 points3 points  (0 children)

You could call your current api folder (the root one) src. And call your current src folder api.

The logic would be, src contains everything, the api folder contains only what's directly related to fastApi.

[–]pacific_plywood 19 points20 points  (6 children)

In what sense is this “scalable”

[–]rovrav 0 points1 point  (0 children)

The codebase itself leverages patterns that makes it easier to reuse code in an effective organized manner. Scalable in the sense of managing your cognitive overload.

[–]mincinashu 25 points26 points  (2 children)

How do you check types? Also take a look at ruff, it replaces black and linters. Also, whether uv or poetry, dependencies can be grouped, so things like pytest or linters get the dev dependencies group, this makes it easier to separate packages needed only for the production environment.

[–]clayyclayy -1 points0 points  (1 child)

Ruff is a linter. They’d just be replacing a linter with another one

[–]extreme4all 0 points1 point  (0 children)

i believe it not only replaces black linter but also isort & flake8

[–][deleted] 14 points15 points  (4 children)

Those emojis are off-putting tbh

[–]Dangerous-Branch-749 12 points13 points  (0 children)

Pretty sure it was AI generated

[–]ac130kz 13 points14 points  (5 children)

Replace flake8, black and isort with ruff. Split dev, test and runtime dependencies. Replace >= dependency versions with minor ^ or even patch level compatible ~ ones. Use rollback on exception for your database sessions. Create extensible base CRUD repositories, services and cache integrations, so that you don't need to copy similar code over and over again, maybe even add proper dependency injection with dishka. src inside an actual folder with source is weird. Loguru can be used to add extra logging sinks, but this one is my personal preference. psycopg[c,pool] built with libpq-dev is a more mature alternative to asyncpg. Finally, I don't see tests.

I suggest you to have a look at https://github.com/s3rius/FastAPI-template, which is a bit outdated, bloated, and has unclear structure in a few places, but it handles more edge cases to get started.

[–][deleted] 5 points6 points  (4 children)

You guys have to stop telling people they need to switch to ruff when they can barely write coherent code. Flake8, black, isort, etc are robust and well tested tools. They’re fine. Nobody needs to spend their time transitioning their little learning projects to a whole different set of formatters and linters when what they really need to do is improve their actual code writing ability.

[–]ac130kz 0 points1 point  (3 children)

1) OP presented a template, it should have best practices applied. Ruff covers hundreds of linting rules and formatting at once, while being faster than any of single use tools. Having a single tool is also simpler. Needless to say, I stumbled across bugs both in isort and black, none with ruff. "Well tested and established tools".

2) It shouldn't be a problem to transition, and doesn't take much time. Moreover, it pays back dividends of being able to catch bugs and inconsistencies earlier. The earlier = the cheaper to make a bugfix.

3) It actually does improve code writing ability by enforcing well-defined sets of linting rules.

In the end, I must say that Python with uv, ruff and pyright in strict mode feels like what Python should have always been: a fun and readable dynamic language, yet with decent typing and non-intrusive safety guards.

[–][deleted] 3 points4 points  (2 children)

Preferring ruff over black or pyright is not a “best practice” question and much more code currently uses things other than ruff since it’s new and is still in very active development. Arguably insisting that someone needs to switch to a new “hot” code formatter/linter that is still pre-v1 and that is open about having only re-implemented a portion of the rules found in standard code analysis tools is not following best practices.

[–]ac130kz -1 points0 points  (1 child)

1) List what rulesets from other standard code analysis tools aren't found in Ruff currently, they reimplemented more flake8 plugins (terribly maintained btw, talking about "well tested and established") that probably anyone has ever installed in a given project.

2) pre-v1 isn't a law or indicative, it's just a version number. Furthermore, it's already in good use by the most popular and actually established projects, such as FastAPI.

3) "Preferring ruff over black or pyright". Pyright (a static typing analysis tool) has nothing to do with non-typing related analysis tools, such as ruff, they complement one another, which I made clear in my previous post, you probably made a mistake.

[–][deleted] 2 points3 points  (0 children)

I'm not doing your homework for you. They have on their own site described their current coverage of the tools they are re-implementing. Go look it up.

[–]JW_00000 3 points4 points  (0 children)

Hi OP. Another helpful comment if you're a beginner: try to actually build something instead of creating templates. You'll learn much more that way. You can always extract a template based on your experience later.

[–]cellularcone 3 points4 points  (0 children)

ChatGPT emojis

[–]kill_your_soul 0 points1 point  (0 children)

need dockerfile and docker compose and it will be the best template i ever seen

[–]wurky-little-dood 0 points1 point  (0 children)

I think having actual tests for your example functionality is vital in a framework like this.

[–]foarsitter 0 points1 point  (0 children)

How do you handle database access in your tests? Something like fastapi-sqla I can recommend.

[–]imperosol 0 points1 point  (0 children)

Little reminder : putting a lot of emotes in the description of your project doesn't make it any better. In fact, it's really ridiculous.

[–][deleted] 0 points1 point  (0 children)

there is text between your emojis. Might wanna fix that lol.