Skip to main content

django-bird

PyPI PyPI - Python Version Django Version

High-flying components for perfectionists with deadlines.

[!IMPORTANT] This library is in active development. Breaking changes may occur before v1.0.0. Use caution in production - pin your dependencies and test thoroughly. All changes, including breaking changes, are documented in the CHANGELOG.

Requirements

  • Python 3.10, 3.11, 3.12, 3.13, 3.14
  • Django 5.2, 6.0, 6.1

Installation

  1. Install the package from PyPI:

    python -m pip install django-bird
    
    # optional: install dj-angles integration helpers too
    python -m pip install 'django-bird[angles]'
    
    # or if you like the new hotness
    
    uv add django-bird
    uv sync
    
  2. Add the app to your Django project's INSTALLED_APPS:

    INSTALLED_APPS = [
        ...,
        "django_bird",
        ...,
    ]
    
  3. Set up django-bird in your project settings:

    # Required: Add the asset finder to handle component assets
    STATICFILES_FINDERS = [
        "django.contrib.staticfiles.finders.FileSystemFinder",
        "django.contrib.staticfiles.finders.AppDirectoriesFinder",
        "django_bird.staticfiles.BirdAssetFinder",
    ]
    
    # Optional: Add templatetags to builtins for convenience
    # (otherwise you'll need to {% load django_bird %} in each template)
    TEMPLATES = [
        {
            # ... other settings ...
            "OPTIONS": {
                "builtins": [
                    "django_bird.templatetags.django_bird",
                ],
            },
        }
    ]
    

    For detailed instructions, please refer to the Configuration section in the documentation.

    [!TIP] For automatic configuration, you can use the django-bird-autoconf plugin.

Getting Started

django-bird is a library for creating reusable components in Django. Let's create a simple button component to show the basics of how to use the library.

Create a new directory named bird in your project's main templates directory. This will be the primary location for your components.

templates/
└── bird/

Inside the bird directory, create a new file named button.html. The filename determines the component's name.

templates/
└── bird/
    └── button.html

In button.html, create a simple HTML button. Use {{ slot }} to indicate where the main content will go. We will also define a component property via the {% bird:prop %} templatetag and add {{ attrs }} for passing in arbitrary HTML attributes.

{# templates/bird/button.html #}
{% bird:prop class="btn" %}
{% bird:prop data_attr="button" %}

<button class="{{ props.class }}" data-attr="{{ props.data_attr }}" {{ attrs }}>
    {{ slot }}
</button>

To use your component in a Django template, use the {% bird %} templatetag. The content between {% bird %} and {% endbird %} becomes the {{ slot }} content. Properties and attributes are set as parameters on the {% bird %} tag itself.

{% bird button class="btn-primary" disabled=True %}
    Click me!
{% endbird %}

django-bird automatically recognizes components in the bird directory, so no manual registration is needed. When Django processes the template, django-bird replaces the {% bird %} tag with the component's HTML, inserting the provided content into the slot, resulting in:

<button class="btn-primary" data-attr="button" disabled>
    Click me!
</button>

You now have a button component that can be easily reused across your Django project.

Documentation

django-bird offers features for creating flexible components, such as:

For a full overview of the features and configuration options, please refer to the documentation.

Motivation

Several excellent libraries for creating components in Django exist:

[!NOTE] Also worth mentioning is django-template-partials from Carlton Gibson. While not a full component library, it allows defining reusable chunks in a Django template, providing a lightweight approach to reusability.

These libraries are excellent in their own right, each solving specific problems in innovative ways: django-components is full-featured and will take most people far with custom components, django-unicorn offers a novel approach to adding interactivity without a full JavaScript framework, and django-cotton has a new way of defining custom components that has me very excited.

So, why another Django component library?

Most of the ones above focus on defining components on the Python side, which works for many use cases. For those focusing on the HTML and Django template side, they have made significant strides in improving the developer experience. However, as a developer with strong opinions (sometimes loosely held 😄) about API design, I wanted a different approach.

After watching Caleb Porzio's 2024 Laracon US talk introducing Flux, I could not shake the desire to bring something similar to Django. While there are plenty of libraries such as Shoelace or UI kits designed for use in any web application, and tools like SaaS Pegasus for whole Django project generation, I couldn't find a well-polished component library solely dedicated to Django templates with the level of polish that Flux has for Laravel.

Initially, I considered contributing to existing libraries or wrapping one to add the functionality I wanted. However, I decided to create a new library for several reasons:

  1. I wanted to respect the hard work of existing maintainers and avoid burdening them with features that may not align with their project's goals.
  2. While wrapping an existing library might have been technically feasible and okay license-wise, it didn't feel right to build an entire component system on top of someone else's work, especially for a project I might want to develop independently in the future.
  3. Building something new gives me the freedom to fully control the direction and architecture, without being constrained by design choices made in other libraries.
  4. Healthy competition among libraries helps drive innovation, and I see this as an opportunity to contribute to the broader Django ecosystem.
  5. Recent libraries like django-cotton and dj-angles are pushing Django templates in new and exciting directions and I wanted to join in on the fun. 😄

It's very early days for django-bird. What you see here is laying the foundation for a template-centric approach to Django components. The current implementation focuses on core functionality, setting the stage for future features and enhancements.

See the ROADMAP for planned features and the future direction of django-bird.

License

django-bird is licensed under the MIT license. See the LICENSE file for more information.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_bird-0.19.0.tar.gz (80.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_bird-0.19.0-py3-none-any.whl (29.4 kB view details)

Uploaded Python 3

File details

Details for the file django_bird-0.19.0.tar.gz.

File metadata

  • Download URL: django_bird-0.19.0.tar.gz
  • Upload date:
  • Size: 80.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for django_bird-0.19.0.tar.gz
Algorithm Hash digest
SHA256 938caa515338501c08cde333651c719d65dc9e6628554b54496a4198c8cae463
MD5 dfd33cff2fab6c4514e626748252237f
BLAKE2b-256 8a1c0b5cadc6afce191c3ed37ea73001b6bd05f3ac92c0b7dd81884dcbab8307

See more details on using hashes here.

File details

Details for the file django_bird-0.19.0-py3-none-any.whl.

File metadata

  • Download URL: django_bird-0.19.0-py3-none-any.whl
  • Upload date:
  • Size: 29.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for django_bird-0.19.0-py3-none-any.whl
Algorithm Hash digest
SHA256 12724fc0a5266f2de5ea11f42d8e990eb9c2be4143edf09c1f71a77d4800e5eb
MD5 fae562a0b9f1a4e74780d363870ea643
BLAKE2b-256 8b5d90f2e9632bb0664c30d65a48a94d672d329547f529bb5182e3ffe26ce451

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.19.0 This release

2 files

0.18.1

2 files

0.18.0

2 files

0.17.3

2 files

0.17.2

2 files

0.17.1

2 files

0.17.0

2 files

0.16.2

2 files

0.16.1

2 files

0.16.0

2 files

0.15.0

2 files

0.14.2

2 files

0.14.1

2 files

0.14.0

2 files

0.13.2

2 files

0.13.1

2 files

0.13.0

2 files

0.12.1

2 files

0.12.0

2 files

0.11.2

2 files

0.11.1

2 files

0.11.0

2 files

0.10.3

2 files

0.10.2

2 files

0.10.1

2 files

0.10.0

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page