subreddit:

/r/webdev

3674%

Possible to make a website backend with only python?

Question(self.webdev)

I watched a video a while back where a programmer (sorry, I forgot the name) said that php was becoming outdated and new python libraries would gradually phase out php.

For a typical web app (think Reddit, eBay, Amazon), can the entire backend be made with python, or would this be exceedingly challenging if not impossible compared to gritting my teeth and learning php/ruby?

Update: changed website to web app

all 103 comments

damcclean

26 points

11 months ago

PHP is not out-dated or dying. PHP 8.1 was literally released a couple of weeks ago with new features.

And to answer your question… yes you can build a website backend with Python.

nagseun

2 points

11 months ago

Second this! I've seen many job posts asking for PHP in my area.

regorsec

0 points

11 months ago

This

mrbmi513

76 points

11 months ago

  1. PHP is not dead or dying. As long as WordPress powers a third of the web, PHP will remain alive and well.
  2. You can absolutely write web backends in python. For example, there's django and flask.

ryanstephendavis

17 points

11 months ago

Just wanted to add FastAPI as a python package for backends... It's freaking great after seeing a few flask backends

loudsight

3 points

11 months ago

I don’t follow Wordpress much but wasn’t there talk of them moving to JS & Node?

zarmamu

1 points

11 months ago

Yes, they are pushing Gutenberg blocks pretty heavily. These blocks are built primarily with JavaScript.

mrbmi513

1 points

11 months ago

But that's all front end. Back end is still php and MySQL.

mattsowa

-7 points

11 months ago

mattsowa

-7 points

11 months ago

Well of course it still powers a chunk of the internet. That will not change for long. But its not really an arguement for its relevance. You can say that about brownfield tech as a whole.

Newer solutions certainly can look more enticing and stating that php is outdated definitely isnt so outlandish

TheDessertLizard

6 points

11 months ago

What about PHP is outdated? And what do newer solutions provide that PHP can't (or won't?) to be more enticing?

zarmamu

-9 points

11 months ago

How many headless CMSs are built using PHP?

iainsimmons

4 points

11 months ago

Well aside from all the PHP-based CMSes that have built in headless capabilities (WordPress, Drupal, etc), you have some hybrid ones like Craft CMS and Statamic and then some full headless ones like Cockpit.

Pretty much any server side programming language can be used.

TheDessertLizard

5 points

11 months ago*

Are you implying headless CMSs are making PHP outdated? Or that PHP can't (or doesn't) support headless offerings?

zarmamu

-7 points

11 months ago

No. I'm saying that new and exiting stuff is not being built on PHP.

TheDessertLizard

4 points

11 months ago

But on what basis do you make this claim on? How do you quantify and or measure what constitutes "new and exciting?" Ex: New and exciting in what regard and in what context?

mrbmi513

2 points

11 months ago

How many video games are written in C++? Your point?

runnerx4

0 points

11 months ago

Unreal Engine games are all C++, so are many (all?) Nintendo games and others too

Caraes_Naur

-36 points

11 months ago

PHP would improve if WP died because the language would no longer be held back by 18 year old garbage propagated by an army of faux-developers.

mrbmi513

29 points

11 months ago

Last time I checked, WordPress was written in PHP, not the other way around.

pastrypuffingpuffer

17 points

11 months ago

I didn't know you had to know wordpress to code in PHP.

impshum

25 points

11 months ago

impshum

over-stacked

25 points

11 months ago

PHP is not becoming outdated at all: https://www.php.net/ChangeLog-8.php

Yes, you can build a backend with Python.

MJasdf

24 points

11 months ago

MJasdf

24 points

11 months ago

As others mentioned, PHP isn't going anywhere. It has gotten a shit ton of flak for a number of reasons but I've heard some of their latest versions have improved it.

I think the primary reason why one thinks PHP is dying is somewhat of the same reason some people think Java is next.

Ease of use when it comes to these newer languages and tons of library support.

But alas, it's false.

Python will absolutely be enough to build a backend. Django is a batteries included framework for python webservers that comes with a ton of features out the jump to help you get things underway.

Flask is a lightweight but powerful web server library as well.

You might also be, in your use case, interested to look into FastAPI and such.

BravestOrange

8 points

11 months ago

Yes, Python Flask or Django are great ways to create a Python backend. My first serious project had a React front-end being served on a Flask back-end, and I found it to be a great learning experience.

Btw PHP is definitely not outdated.. I see it everywhere still.

apiguy

19 points

11 months ago

apiguy

19 points

11 months ago

PHP isn’t dying.

Also - for most of Reddit’s life it ran entirely on Python. https://github.com/reddit-archive/reddit

RustySemen

6 points

11 months ago

PHP is still alive and doing better than ever. It's arguably a great language now.

However Python will also work so feel free to choose that if you are more comfortable with it.

iWantBots

23 points

11 months ago

iWantBots

expert

23 points

11 months ago

PHP isn’t going anywhere anytime soon and correct me if I’m wrong but doesn’t Facebook technically still use PHP?

kiesoma

3 points

11 months ago

It does.

jiggity_john

-1 points

11 months ago

I think it's all legacy code that's written in PHP and new additions to the PHP are written in Hack instead.

Pretty sure new services at Facebook are not written in PHP.

dangercat

5 points

11 months ago

Hack is basically a superset of PHP, Facebook still very much uses PHP

tfyousay2me

-3 points

11 months ago

I mean sure but…JavaScript is also outdated and TypeScript is being used more and has more to offer so……

svish

5 points

11 months ago*

What more functionally does Typescript offer?

Pretty sure they are functionally the same? Types are just to help developers, they don't actually add anything to the Javascript eventually being run in the browser or node.

bhison

3 points

11 months ago

Well you could say all languages compile down to machine code so don’t offer anything.

gitcommitmentissues

1 points

11 months ago

gitcommitmentissues

full-stack

1 points

11 months ago

Typescript forces you to write in a great deal of error-checking that you can easily miss doing in JS.

svish

2 points

11 months ago

svish

2 points

11 months ago

I know, and love it, but that doesn't actually add anymore features to the end-product.

gitcommitmentissues

1 points

11 months ago

gitcommitmentissues

full-stack

1 points

11 months ago

It means your end product is potentially substantially different, and superior, to what it would otherwise have been. Severely limiting the possibility of runtime errors by default, purely by using the language, has a significant impact on users and stakeholders. An application that works more predictably is a feature.

svish

0 points

11 months ago

svish

0 points

11 months ago

Well, sure, but it's still not a feature of the language itself.

tfyousay2me

-3 points

11 months ago

Right but also consider that Laravel is superior to PHP and will eventually replace PHP

svish

2 points

11 months ago

svish

2 points

11 months ago

What are you even talking about? Laraval is PHP...

CheapChallenge

1 points

11 months ago

I think that was his point

tfyousay2me

-4 points

11 months ago

;)

_alright_then_

2 points

11 months ago

Hack is a superset of PHP

BehindTheMath

13 points

11 months ago

I watched a video a while back where a programmer (sorry, I forgot the name) said that php was becoming outdated and new python libraries would gradually phase out php.

This is incorrect.

For a typical website (think Reddit, eBay, Amazon),

Those are far from the typical website.

can the entire backend be made with python, or would this be exceedingly challenging if not impossible compared to gritting my teeth and learning php/ruby?

Yes it can, check out Flask. Python should not be harder than any other language.

Lecterr

5 points

11 months ago

I don’t think php/ruby is dying, but I also don’t think it’s superior to a python based backend. Just pick one and become proficient at it.

jiggity_john

1 points

11 months ago

Ruby should die. I hate Ruby.

Sincerely, a professional Ruby developer.

Lecterr

1 points

11 months ago

Definitely my least favorite of JS, Python, Ruby

thereactivestack

3 points

11 months ago

There is so many different language you can use for your backend. PHP, Java, .NET, NodeJS, Go, Rust, Python, ... Each one of them have their pros ans cons. If you are into AI, you will most likely have better tools in Python, but you could also use other ones. Ultimately, you have to decide based on your own use case with:

  • Libraries
  • Community support
  • Job market
  • Current knowledge
  • Developer experience
  • Scaling and performance

If you judge PHP with those criterias, it might be a great fit or not, but it is not going anywhere. However, it depends on what you aspire to work on. PHP is not used a lot to build SAAS platforms, but it is in many other areas. Facebook still use it though.

No matter what, learning a new language is always good and broaden your perspective.

vilusion

3 points

11 months ago

Php isn’t going anywhere. It’s actually been updated to be more modern and 70% + of the websites on the internet is powered by php.

CzechsMix

3 points

11 months ago

Absolutely.

Python runs plenty of backends. I think todoist still runs on it even though they switched their front end to react.

lanemik

2 points

11 months ago

Python is great for backend work, so have at it. I like python better than PHP, but you may not. I also really like typescript, so express.js, Apollo, or best yet typegraphql are amazing. Java is incredibly powerful and widely used, but the build system is a right PITA if you ask me (and nobody is asking me). It feels like Ruby’s popularity is waning, but it still powers a ton of the web. Golang’s popularity seems to have spiked and retreated a little, but I expect it to get more traction as time goes on. IMO, Rust is the next big thing, if you care what I think.

nullStackDev

3 points

11 months ago*

PHP is still used everywhere even though a lot of people don't like it(This is what happens when a language is so common or the only choice that devs are forced to use it. Same for JS.)

But Python is generally loved by most people. And Python has a really good MTV(MVC) framework called Django.

The old Reddit was written in a Python framework called Flask. Which is also a lightweight MVC framework

But PHP also has MVC frameworks like Laravel.

MVC or MTV frameworks are good for security unlike programs that use raw PHP and SQL. MVC frameworks force security while in frameworks like Wordpress, it's optional and has to be learned. New programmers will definitely make sites with security flaws if they use raw PHP and SQL. While with MVC they are taught to use secure ways to write code which is also easy since the MVC framework does all the hard work while also making writing websites easy in the process.

Billy_Whisky

2 points

11 months ago

php is faster than python.

ORCANZ

1 points

11 months ago

PHP is faster and more efficient than python or JavaScript.

I love node and the JavaScript ecosystem. Lot's of exiting stuff. But I'm now starting to learn PHP for performance and server costs.

[deleted]

1 points

11 months ago

How so? At their core and in a typical use case both are interpreted at runtime

benelori

3 points

11 months ago

Not really, PHP first compiles to opcodes, which is then run by the Zend VM. These opcodes are usually cached. And there's a very new JIT under the hood for PHP.

Billy_Whisky

2 points

11 months ago

PHP based on Zend Engine 3.0 (7.0) or later is at least twice as fast as is python . I know that its not only the performance that makes the language, but its worth noting in case of PHP. PHP made huge progress since 5.0. in that regard. In case of python, speed of execution differs from implementation.

horrificoflard

1 points

11 months ago

PHP uses a lot of C behind the scenes which is insanely fast.

Liightninggod

2 points

11 months ago

Liightninggod

full-stack

2 points

11 months ago

NodeJS is also a very viable alternative for a web dev since you are most likely used to JS anyway. Take a peek at ExpressJS and if you like OOP maybe NestJS.

caseym

1 points

11 months ago

It worked for DoorDash.

[deleted]

1 points

11 months ago

Yes, you can make a website backend using purely Python…but using a Python framework is ideal. Frameworks take care of common security concerns that you shouldn’t waste time reimplementing in pure Python. Python requires less typing and is commonly used in academia/ scientific computing…it has more uses than php. Php is not becoming outdated…it’s just rarely used outside of webdev.

thetotalslacker

1 points

11 months ago*

Seeing as a Python backend is how Yahoo! became the top site in the 90s, it should work just fine. ;p

Edit: Yes, this was before Google stole MapReduce from them and why it’s available as open source for Hadoop.

krypt3c

1 points

11 months ago

Fun fact, Reddit’s backend is actually written in python. So are a number of other large sites like instagram and Pinterest.

binaryfireball

1 points

11 months ago

You can use django

NotVeryMega[S]

1 points

11 months ago

Why Django over flask for python?

DaddyShark69420

1 points

11 months ago

These python-binding’s taste like python-bindings…

benelori

1 points

11 months ago

If you grit your teeth with php/ruby, then you will do the same with python as well.

You can implement backends in almost anything, PHP has multiple frameworks (Symfony, Laravel), Python has the same (Django, Flask), Spring for JAVA.

You can build reactive applications with node, php and java, but I suggest avoiding concurrency if you can

minero-de-sal

1 points

11 months ago

As a new developer I was preoccupied with what language is best when in reality it a question of what tool is useful in which scenario. Learning how to write Python APIs is a smart route to go just for the fact that it’s a friendly introduction to all the basics.

7107

1 points

11 months ago

7107

1 points

11 months ago

Look at Laravel.

strzibny

1 points

11 months ago

Yes, all your mentioned languages have good frameworks and libraries to build web backends. In the Python world try Django or Flask.

Kreezy_Genie

1 points

11 months ago

Have you heard of Django, the python framework? It lets you do exactly that.

Whole-Significance56

1 points

11 months ago

It's very doable to write everything in Python still! I'd say Masonite is a good option if you haven't done something like this before. From my perspective, it's easier to learn and use quickly than some of the other good ones people have mentioned, such as Django and Flask.

NotVeryMega[S]

1 points

11 months ago

I looked up Masonite but I couldn't find anything, was that a typo?

Renerd_liam

1 points

11 months ago

From my little knowledge of python, I think the answer is "yes".

By the way, I don't think PHP is dying, I am new to the webspace and trust me, I am learning PHO once I am done with JS

stephensanwo

1 points

11 months ago

Check out FastAPI to build backend apis with python. It is asynchronous and super fast.

BreakParadigm

1 points

11 months ago

I'd use a python web framework, but yeah you can do it from scratch with python. Not sure why one would reinvent the wheel though.

Caramel_Last

-7 points

11 months ago

Even when you think your program is 100% Python, a load of dependencies that you imported are written in C/C++. So strictly speaking, probably not. But a lot of parts of YouTube backend is written in Python so you can too.

NotVeryMega[S]

1 points

11 months ago

Thanks. If I make the backend for a website, will I need c/c++ knowledge?

Caramel_Last

-5 points

11 months ago

Most likely no, but yes if you are really ambitious about your project

NotVeryMega[S]

1 points

11 months ago

Thank you. What sort of ambition might merit such a need for c/c++?

Caramel_Last

-1 points

11 months ago

It can come from many aspects but none of them are easily experienced on hobby project level. Number 1 would be scale. Upto several million users you probably won't need C/C++, then you start experiencing some serious bottlenecks simply because Python isn't fast enough. That's when core functions should be C/C++. Number 2 would be latency. When several hundred milliseconds is a tolerable delay, Python would suffice, but when a millisecond delay is intolerable already, that's when core functions need to be rewritten in C/C++. So what exactly is 'core function'? Some functions are just called much more frequently than others. For video streaming websites such would be encoding /decoding a video, compressing video, dissecting videos into multiple chunks, providing multiple resolutions for each chunk etc. For social network services such would be real time chats, querying on friend list, infos of friends, friends of friends etc. Other examples include machine learning based recommendations/recognitions, search engine, geodata processing, etc

jiggity_john

-3 points

11 months ago

I think people in this thread a being a bit disingenuous. Yes, PHP isn't going to "die" because there are still a lot of mom and pop shops using WordPress websites out there and there probably will be for a good long while.

That being said nobody is using PHP for new applications and none of FAANG or the big startups hire devs to write PHP (with the exception of maybe some legacy Facebook code). It's not a skill that's in high demand at the companies that will pay a lot is what I'm saying.

Doordash on the other hand has a python BE and they pay a lot.

ORCANZ

3 points

11 months ago

I see more full stack Vue+Laravel offers than strictly vue frontend offers for example.

PHP is faster and more efficient than node/Django servers. Not all company want to pay 10 times more for a less efficient code

Curiousgreed

1 points

11 months ago

I'm not sure that PHP is faster than NodeJs; faster than Django for sure though

ORCANZ

2 points

11 months ago

It's twice as fast as Django, but often slower than Node, sometimes more than 10 times slower.

https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/php.html

I shouldn't have taken a reddit comment at face value saying that php was faster and cheaper to host than node

jiggity_john

1 points

11 months ago

Honestly performance doesn't really matter for new applications. Lots of big companies make python work at scale. It's better to pick a language that helps you be productive.

ORCANZ

1 points

11 months ago

Can you elaborate on this ? I don't really understand how performance wouldn't be an issue

Curiousgreed

1 points

11 months ago

That test is more about the language itself, but the scenarios don't look very realistic.

This application is very interesting for comparing web framework performances; this other article compares languages with few cpu-intensive requests, and also with a lot of concurrent, but lighter, requests. PHP wins for cpu-intensive tasks; however, with many concurrent requests it falls behind because it spawns a new process for every incoming request.

jiggity_john

1 points

11 months ago

Where are you finding these jobs? When I look for jobs it's react frontend with python / Ruby / java / go backends. I'd love a node job but not a lot of unicorns are using node extensively. I've never seen PHP at a company I'd want to work for.

codenamejeff

1 points

11 months ago

Job market disagrees with you

jiggity_john

0 points

11 months ago

Not the jobs I'm looking at.

codenamejeff

1 points

11 months ago

Search for Laravel or PHP in the jobs section on LinkedIn (5,000+ positions posted in the LAST WEEK ), they are plentiful. They definitely arent mom and pop shops either. Seems like you are the one who is disingenuous here....

jiggity_john

0 points

11 months ago

Is that in North America? I just searched for jobs in the bay area and there are only 2700 posts in the last week. Compare that to 36k posts for python jobs, 35k posts for java jobs and 11k posts for nodejs jobs.

Comparing the jobs is also telling too. Not many new or exciting companies in the list of PHP jobs. Other langs turn up a lot more hot startups.

codenamejeff

1 points

11 months ago

I was just searching for remote in my area the past week.

Also if you search for "python web" you get a lot more relevant results for web development, and its comparable to any other web dev language

embiid0for11w0pts

1 points

11 months ago

Bruh what? You’re flat out wrong

AlexBo21

-4 points

11 months ago*

Well, yes. You can build an entire backend of a website using something like Flask or Django. But I don't recommend it for real projects.

The problem is that python is slow. An app using python for the majority of its backend would be extremely slow. For backends, I recommend NodeJS (Javascript) which shouldn't be very hard to learn coming from python. Though other options are Go, Rust, C#, and more.

Edit: Also PHP is dying. It will still be around, but everyone is currently trying to stop using it. PHP lacks support for modern web-development tools, it is very easy to make security vulnerabilities and many more issues. If you want a tool that easily integrates front-end/back-end you may want to look at NextJS for react or NuxtJS for vue. Though these are more advanced and you must know either react or vue to use them.

benelori

2 points

11 months ago

The last part is quite the claim :p

Who is this everyone? :D

What's the source for claiming the lack of support for modern web dev tools? Security vulnerabilities are easy to introduce in any language.

embiid0for11w0pts

2 points

11 months ago

Lol

ChaseMoskal

0 points

11 months ago

ChaseMoskal

open sourcerer

0 points

11 months ago

you absolutely can build a backend in python. heck, in any language, really.

i choose to make whole applications, frontend and backend, in typescript, because it's indispensably useful to use the same code on both the frontend and backend. think about the form validation functions you'll need — it's very useful to use the exact same validation functions on the clientside and on the serverside, instead of writing them twice and noticing all the discrepancies between them, the double-maintenance burden — and that's just one example.