How to create a third-party library for Django? ( Short article )

How to create a third-party library for Django? ( Short article )

Would you like to know how to make a third-party package for Django? Follow this article

ยท

2 min read

Have you ever thought of building a library for Django itself?

Or do you have an idea that you want to implement in the form of a library for Django?

In this article, we're going to learn how to build a third-party package for Django, and you'll see that it's the easiest thing in the world!

As you know, you can create an app in Django with the python manage.py startapp APP_NAME command and import it into your program. And that's all you need to build a third-party library for Django! ( Just start an app ).

Build a Django app

You only need one app and you don't need any other Django project files. As a result, you can create this app manually by yourself or create a project using the django-admin startproject core . command and then create an app with the python manage.py startapp APP_NAME command. And now you can make your package in the form of this app.

Third-party package structure

โ”œโ”€โ”€ admin.py
โ”œโ”€โ”€ apps.py
โ”œโ”€โ”€ __init__.py
โ”œโ”€โ”€ migrations
โ”‚   โ”œโ”€โ”€ 0001_initial.py
โ”‚   โ””โ”€โ”€ __init__.py
โ”œโ”€โ”€ models.py
โ”œโ”€โ”€ serializers.py
โ”œโ”€โ”€ tests.py
โ””โ”€โ”€ views.py

As you can see, it is exactly the structure of a normal Django app.

After you've developed it and prepared your package, you can copy it into another Django project, then you'll see that everything works!

But to place your package on a site like PyPI, you need another series of files( like setup.py ). Also, your app should be in an independent folder outside of any Django project.

See this article for more information on how to upload your package to the PyPI site.

Final word

As you can see, making a third-party package for Django is one of the easiest things in the world!

This is a short article to explain the path of making a Django package, a path that confused me for a while, how to make a third-party package for Django? I hope that if you had this question in your mind, you have now found the answer.

ย