This week we welcome Sebastián Ramirez (@tiangolo) as our PyDev of the Week! Sebastián is the creator of the FastAPI Python web framework. He maintains his own website/blog which you should check out if you have some free time. You can also see his open source projects there. You can also see what projects he is contributing to over on Github.
Let's take a few moments to get to know Sebastián better!
Can you tell us a little about yourself (hobbies, education, etc):
Hey! I'm Sebastián Ramirez, I'm from Colombia, and currently living in Berlin, Germany.
I was "homeschooled" since I was a kid, there wasn't even a term for that, it wasn't common. I didn't go to school nor university, I studied everything at home. At about (I think) 14 I started fiddling with video edition and visual effects, some music production, and then graphic design to help with my parent's business.
Then I thought that building a website should be almost the same ...soon I realized I had to learn some of those scary "programming languages". HTML, CSS, and JavaScript ("but!!! HTML and CSS are not..." I know, I know). But soon I was able to write a very short text, in a text file, and use it to make a browser show a button, that when clicked would show a pop-up saying "Hello world!"... I was so proud and excited about it, I guess it was a huge
"I maked these" moment for me. I still feel that rush, that excitement from time to time. That's what makes me keep loving code.
I also like to play videogames and watch movies, but many times I end up just coding in my free time too. I'm boring like that...Â
Why did you start using Python?
At some point, I was taking several (too many) courses on
Coursera,
edX, and
Udacity. I knew mainly frontend vanilla JavaScript (Node.js was just starting), so I did all the exercises for the Cryptography, Algorithms, and other courses with JavaScript running in a browser, it sounds a bit crazy now.
Then I took Andrew Ng's ML course on Coursera, it used Octave (kinda Matlab) and it taught me enough Octave/Matlab for the course, and also that learning a new language was not so terrible. But then an AI course from Berkeley/edX required Python... so I took the Python crash course that was embedded (it was just like one page). And I went into the AI course with that. I loved the course, and with it, I started to love Python. I had to read a lot of Python docs, tutorials, StackOverflow, etc. just to be able to keep the pace, but I loved it. After that, I took an MIT/edX Python course and several others.
And I just kept learning and loving Python more and more.
What other programming languages do you know and which is your favorite?
I'm quite fond of JavaScript as it was my first language. I have also used some compile-to-JS languages like CoffeeScript, TypeScript. I have also ended up doing quite some Bash for Linux and Docker.
I really like TypeScript, and now I almost never do plain JS without TS, I love having autocompletion everywhere and type checks for free. I naturally got super excited when optional type hints for Python were released as a Christmas gift in 2016. And 2 years later FastAPI came to be, heavily based on them.
What projects are you working on now?
I put a lot of my free time to
FastAPI and sibling projects, and also some of the other open source tools I've built.
Right now I'm working for
Explosion AI. They are the creators of
spaCy, the open source, industrial-strength, Natural Language Processing package.
At work, I'm currently on the team building the teams version of
Prodigy, a commercial tool for radically efficient machine teaching, using Active (Machine) Learning.
But as open source is very important for the company (because they're awesome like that), I also devote part of my working time to FastAPI and family.
Which Python libraries are your favorite (core or 3rd party)?
Core, I would say
typing, as it's relatively new and it deserves more attention, I think not many people know that those optional type hints are what powers autocompletion and automatic type checks for errors in editors. Most of the developers love those features, but a few know that type hints are what powers them.
But I think Pydantic also deserves a lot more attention, even outside of FastAPI. It's an amazing library, really easy to use, and saves a lot of time debugging, validating, documenting, and parsing data. It's also great for managing application settings and just moving data around in an app. Imagine using deeply nested dicts and lists of values, but not having to remember what is what everywhere ("did I write 'username' or 'user_name' as the key in the other function?" ), just having autocomplete for everything and automatic error checks (type checks).
I recently built aÂ
GitHub action to help me manage issues, and most of the work ended up being done automatically by Pydantic. It also works great for data science, cleaning and structuring data.
This list could probably grow a lot, but some highlights:
- Dev utils: Poetry or Pipenv, Black, Isort, Flake8, Autoflake8, Mypy, Pytest, Pytest-cov
- For docs: Mkdocs with Mkdocs-material and Markdown-include
- Others: Cookiecutter, Requests or HTTPX, Uvicorn
- Data Science/Processing, ML: Keras with TensorFlow or PyTorch, Numpy, PyAV, Pandas, Numba, and of course, spaCy and Prodigy
Is there anything else you'd like to say?
I love the Python community, I think it's a friendly ecosystem and I would like all of us to help it be even more welcoming, friendly, and inclusive. I think we all can help in achieving that.
New developers: don't be shy, you can help too. Updating documentation of a new tool you are learning is a great start.
Maintainers: help us build a friendly ecosystem, it's difficult for a new developer to come and try to help. Please be nice.
How did your project, FastAPI, come about?
I had spent years finding the right tools and plug-ins (even testing other languages with their frameworks) to build APIs.
I wanted to have automatic docs; data validation, serialization, and documentation; I wanted it to use open standards like OpenAPI, JSON Schema, and OAuth2; I wanted it to be independent of other things, like database and ORM, etc.
I had somewhat achieved it with some components from several places, but it was difficult to use and somewhat brittle, as there were a lot of components and plug-ins, and I had to somehow make them interact well together.
I also discovered that having types as, in TypeScript, it was possible to have autocompletion and checks for many errors (type checks). But then Python added optional type hints!
And after searching everywhere for a framework that used them and did all that, and finding that it didn't exist yet, I used all theÂ
great ideas brought by previous tools with some of mine to integrate all those features in a single package.
I also wanted to provide a development experience as pleasant as possible, with as small/simple code as possible, while having great performance (powered by the awesome tools underneath, Starlette and Pydantic).
What top three things did you learn while creating the package?
First, that it was possible. I thought building a package that others found useful was reserved for some olympian-semi-god coders. It turns out that if there's something to solve, and you solve it, and you help others use it to solve the same thing, that's all that is needed.
Second, I learned a lot about how Python interacts with the web. FastAPI uses the new standard
ASGI (the spiritual successor to WSGI), I learned a lot of it. Especially reading the beautiful and clean code ofÂ
Starlette.
Third, I learned a lot about how Python works underneath by adding features toÂ
Pydantic. To be able to provide all its awesome features and the great simplicity while using it, its own internal code has to be, naturally, very complex. I even learned about undocumented features of Python's internal typing parsing, that are needed to make everything work.
But I don't think that a new developer needs to learn the last 2 things, the first one is the most important one. And as I was able to build FastAPI using the great tools and ideas provided by others, I hope FastAPI can provide a simple and easy way for others to build their ideas.
Do you have any advice for other aspiring package creators?
Write docs for your package. It doesn't exist completely if it's not well documented. And write them from the point of view of a new user, not of your own.
Also, building and publishing a new package is now extremely easy. Use
Flit or
Poetry if your project is simple enough to use them (i.e. pure Python, you are not building with Cython extensions, etc).