r/learnpython • • Oct 20 '24

Please tell me good resources for creating api in python

As title suggests, please tell me good resources for creating api in python

1 Upvotes

27 comments sorted by

18

u/samreay Oct 20 '24 edited Oct 20 '24

The trick to a good API isn't what's under the hood (though I second FastAPI/Starlite) but it's in the design of the API itself. How its endpoints are configured, how authentication works, documentation, examples, pagination, and other design patterns.

For a web resource, you could check out Google's API design guide, and for a paid book I'd recommend JJ Geewax's API Design Patterns

Of course this is getting into the weeds, so if this is a just for fun thing, just play with FastAPI :)

1

u/xav1z Oct 20 '24

could you recommend books on python in general? im learning Effective Python now, just started but liking it

1

u/samreay Oct 21 '24

Unfortunately I'm not too familiar with good resources for those just starting out, apologies.

1

u/xav1z Oct 21 '24

that's ok, no worries ✌️

0

u/Gullible-Access-2276 Oct 20 '24

Thanks for the resources. I will go through the book. 

1

u/Possible_Lynx1854 17d ago

I jast stat naww

4

u/sonobanana33 Oct 20 '24

What does it even mean?

Do you want to create an API to your library? A REST API? You want advice on how to structure the function calls???

1

u/Gullible-Access-2276 Oct 20 '24

I have a small dummy database containing employees_salary data. I was wondering how would I create an api so that the data can be shared as json object. 

5

u/sonobanana33 Oct 20 '24

Ah, you mean a REST API, not just an API.

I'd look into flask or django.

2

u/JohnnyJordaan Oct 20 '24

I would look at FastAPI with a simple SQL framework like SQLModel (bridging SQLAlchemy with Pydantic Models that are directly servable by FastAPI): https://sqlmodel.tiangolo.com/tutorial/fastapi/simple-hero-api/

3

u/m0us3_rat Oct 20 '24

creating api in python

without more context this alone is fairly vague.. it can mean a few things.

can you specify what would you like to achieve?

what would be the interactions you are interested in?

at face value any of the web frameworks can do .. that.

so you usually pick the one that you know better.

unless you actually have million of concurrent users each of them will be virtually identical performance.

2

u/Gullible-Access-2276 Oct 20 '24

This is merely for a hobby project

3

u/m0us3_rat Oct 20 '24

then any of them will do.

pick the one you like working with best.

2

u/ReachingForVega Oct 20 '24

You can do it with flask. If you want easy database integration django is a good option. 

2

u/[deleted] Oct 20 '24

You can use the import requests module to get APIs from different websites

1

u/Gullible-Access-2276 Oct 20 '24

I have used few APIs from various YouTube tutorials like weather api etc.  But I am keen to learn to create api so that i can share data from my server

2

u/FoolsSeldom Oct 20 '24

Check out RealPython.com - lots of greate guides and article (mostly free to access).

2

u/xiongchiamiov xiongchiamiov Oct 20 '24

Build an example client. This will quickly reveal to you what the API should provide.

2

u/Material-Reserve6276 Aug 04 '25

I agree with many of the comments here. Start with building your API in Python using FastAPI. It is quite easy to use and automatically generates docs via OpenAPI. You can also go through Google API Design guide for best practices.

1

u/Gullible-Access-2276 Oct 20 '24 edited Oct 20 '24

I am doing programming as a hobby and try to improve my skillset. So far I have done some gui projects, manipulated folders, files, crud operations in mysql and sqlite. Some regex and web scrapping. I am from non computer science background. So far learnt through udemy courses and youTube videos. I have done vba programming, ahk and python. Learning little bit of c also. I have not much clue regarding networking and lower level computer architecture and organization related details. I want to eventually pick up those concepts also. Perhaps I need to understand networking in depth before learning api concepts?

4

u/Maximus_Modulus Oct 20 '24

You don’t need to know networking although very high level concepts are always useful. I’m a programmer and former networking engineer. . Most programmers know very little about networking in depth.

1

u/Gullible-Access-2276 Oct 20 '24

Thanks for your valuable inputs. 

I saw one course from TalkPython and it was regarding APIs. So from my understanding, APIs are used for transferring only text/string information using soap/xml and rest/json formats. For sending multi media content like jpegs, MP4, mp3 etc is done only through http? 

Also api is used for authentication for logging to different sites using gmail credentials

I guess if I sell a paid app and if I were to verify whether the app user is legit then from app I can use api and check with my database if the user has purchased my app and validy of license etc? 

Please correct me if I am wrong in my understanding

1

u/Gullible-Access-2276 Oct 20 '24

Also to access data and functions between different programming languages like c and lua, we use APIs

Streaming data from raspberry Pi, cctv, drone, zoom like software are not done through APIs right. I think they're done through http protocols.