Skip to main content

Blogging for FastAPI

Project description

FastAPI Blog

A simple, easy-to-use blog application built with FastAPI.

Features

  • Write blog posts in Markdown
  • Syntax highlighting for code blocks
  • Responsive design
  • Dark mode
  • Overloadable templates
  • Live, working configuration examples
  • RSS feed
  • SEO-friendly
  • Sitemap
  • Docker support

Basic Usage

  1. Import the add_blog_to_fastapi function
  2. Run the instantiated FastAPI app throught the add_blog_to_fastapi function

This all you need to do:

from fastapi_blog import add_blog_to_fastapi
from fastapi import FastAPI


app = FastAPI()
app = add_blog_to_fastapi(app)


@app.get("/")
async def index() -> dict:
    return {
        "message": "Check out the blog at the URL",
        "url": "http://localhost:8000/blog",
    }

Advanced Usage

fastapi_blog is configurable through the add_blog_to_fastapi function.

Replacing the default templates

This example is Django-like in that your local templates will overload the default ones.

import fastapi_blog
import jinja2
from fastapi import FastAPI


django_style_jinja2_loader = jinja2.ChoiceLoader(
    [
        jinja2.FileSystemLoader("templates"),
        jinja2.PackageLoader("fastapi_blog", "templates"),
    ]
)

app = FastAPI()
app = fastapi_blog.add_blog_to_fastapi(
    app, prefix=prefix, jinja2_loader=django_style_jinja2_loader
)


@app.get("/")
async def index() -> dict:
    return {
        "message": "Check out the blog at the URL",
        "url": f"http://localhost:8000/blog",
    }

Changing the location of the blog url

Perhaps you want to have the blog at the root?

import fastapi_blog
from fastapi import FastAPI


app = FastAPI()
app = fastapi_blog.add_blog_to_fastapi(
    app, prefix="change"
)


@app.get("/api")
async def index() -> dict:
    return {
        "message": "Check out the blog at the URL",
        "url": "http://localhost:8000/change",
    }

Installation and Running Example Sites

Option 1: Local Virtualenv

You can install this into a virtualenv using the pyproject.toml file:

pip install fastapi-blog
make run

Option 2: Docker (Local Dockerfile)

Or into a Docker container using the local Dockerfile:

docker build -t fastapi-blog .
docker run -d -p 8000:8000 fastapi-blog

Option 3: Docker (Prebuilt)

Or using a prebuilt Docker image from GitHub Container Registry:

docker run -d -p 8000:8000 ghcr.io/aroygreenfeld/fastapi-blog:latest

This is if you just want to run the application without building it yourself.

Releasing a new version

  1. Update the version in pyproject.toml and fastapi_blog/__init__.py

  2. Build the distribution locally:

pip install -U build
python -m build
  1. Upload the distribution to PyPI:
pip install -U twine
python -m twine upload dist/*
  1. Create a new release on GitHub and tag the release:
git commit -am "Release for vXYZ"
make tag

Project details


Download files

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

Source Distribution

fastapi-blog-0.3.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

fastapi_blog-0.3.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file fastapi-blog-0.3.0.tar.gz.

File metadata

  • Download URL: fastapi-blog-0.3.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.1

File hashes

Hashes for fastapi-blog-0.3.0.tar.gz
Algorithm Hash digest
SHA256 d1ec27ca26724dcc8601d7f72a02f7c471b7824d1f7e10d4ec066f6e2c8c5381
MD5 2f24b2c85feb9d89ba108e1e8c265b58
BLAKE2b-256 b48467f128e6c13f9f9f91624b222a43f34991f781c2019dda3b19eed77fff45

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_blog-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 88c69f0d25ab943243da19614b23cc76023c1124493e53828cb71fbef950cf41
MD5 d56c7bf4ac8c0ea88f93caa6d3d26eb5
BLAKE2b-256 5b7ae3104b5d20017f1395b613610a2d704dd415464162c8c8ce151099b13cc1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page