Skip to main content

Flask-Collections

Static collections for Flask. Inspired by Jekyll collections.

Installation

pip install flask-collections

Usage

from flask import Flask
from flask_collections import Collections

app = Flask(__name__)
collections = Collections(app)

Creating collections

Multiple collections can be created. Each collection has a set of entries.

Each entry has a "slug", some content and a set of properties. Formats for each entries varies depending on the collection type.

When the is_markdown property is set to true (which is automatic if a file-based entry has the .md extension), the content is rendered as markdown.

When using a filename, it can contain a date prefix in the form of YYYY-MM-DD. The date will be available as the date property.

File-backed collections

In a directory named after the collection located in collections, use one file per entry.

Example:

collections
  blog/
    2025-01-01-new-year.md
    2025-02-01-second-month.md

Example 2025-01-01-new-year.md:

---
title: "Happy new year!"
---
Hello world

Data-backed collections

These are collections where entries are all stored in a single structed file like CSV, JSON or YAML.

Example collections/blog.csv:

slug,date,title,content
new-year,2025-01-01,"Happy new year!","Hello world"

An sqlite database can also be used using the .db extension. A table or query must be provided a config.

Configuring collections

Collections can be configured under the COLLECTIONS key. Create a subkey named after the collection that contains a dict of options.

By default, collections are bound to a url under a path named after the collection. This can be overriden using the url config key.
You can also provide a layout template for collection entries. This template will receive an entry and content variable.

collections:
    blog:
        url: /blog
        layout: layouts/post.html
    categories:
        path: meta.db
        table: categories

To prevent a collection from being exposed via a URL, set url to false.

Accessing collections programmatically

Collections are accessible under app.collections.

for post in app.collections.blog:
    print((post.slug, post.title, post.url))

Metadata

Release files for flask-collections 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flask-collections 0.3.0
File Size Uploaded
flask_collections-0.3.0.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flask-collections 0.3.0
File Interpreter ABI Platform
flask_collections-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.2 kB

Release files / flask_collections-0.3.0.tar.gz

Download URL flask_collections-0.3.0.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e0a3b56298ba9081393a6a7bcaafbcedaed66e721017a5c52c3206182eab3de2
BLAKE2b-256 checksum
How to use checksums
9b7286310704ca4bf2cad505e8ffd18c4f85c473e6fd449c66fec3c7b1e94f22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.17

Release files / flask_collections-0.3.0-py3-none-any.whl

Download URL flask_collections-0.3.0-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b798a3b9a2f85fc821aaf77a0f9480026a8f6922b8d37f7b5ad3e7dc8fa45be3
BLAKE2b-256 checksum
How to use checksums
568b03f358e98159d17518248aeef7c4ba21a95f5eeedf0a27ea0b870daaa517
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.17

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page