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))

Download files

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

Source Distribution

flask_collections-0.3.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

flask_collections-0.3.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file flask_collections-0.3.0.tar.gz.

File metadata

  • Download URL: flask_collections-0.3.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for flask_collections-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e0a3b56298ba9081393a6a7bcaafbcedaed66e721017a5c52c3206182eab3de2
MD5 0460f9e6cf21e1610e63b8be9e225143
BLAKE2b-256 9b7286310704ca4bf2cad505e8ffd18c4f85c473e6fd449c66fec3c7b1e94f22

See more details on using hashes here.

File details

Details for the file flask_collections-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_collections-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b798a3b9a2f85fc821aaf77a0f9480026a8f6922b8d37f7b5ad3e7dc8fa45be3
MD5 3a69719275041fda5586b68467be78dd
BLAKE2b-256 568b03f358e98159d17518248aeef7c4ba21a95f5eeedf0a27ea0b870daaa517

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 files

0.2.1

2 files

0.2.0

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