Skip to main content

Optimizer (Python)

Port em Python do pacote PHP coffeecode/optimizer de Robson V. Leite. Gera tags <head> para SEO, Open Graph, Twitter Card e Facebook com uma API fluente — direto ao ponto, sem dependencias.

Python port of the PHP package coffeecode/optimizer by Robson V. Leite. Builds <head> tags for SEO, Open Graph, Twitter Card, and Facebook through a fluent API. Zero dependencies.

Destaques

  • API fluente: optimize → publisher → open_graph → twitter_card → facebook → render
  • Tags <title>, <meta>, <link rel=canonical> com escape automatico
  • Acesso aos dados via atributos: op.title, op.description, op.url, op.image
  • Pure Python — sem dependencias de runtime

Instalacao

pip install coffeecode-optimizer

Requer Python >= 3.9.

Uso

from coffeecode_optimizer import Optimizer

op = (
    Optimizer()
    .optimize(
        title="Optimizer Happy and @CoffeeCode",
        description="Is a compact and easy-to-use tag creator to optimize your site",
        url="https://www.upinside.com.br/coffeecode/optimizer/example/",
        image="https://www.upinside.com.br/uploads/images/example.jpg",
    )
    .publisher("upinside", "robsonvleite")
    .twitter_card("@robsonvleite", "@robsonvleite", "upinside.com.br", "summary_large_image")
    .open_graph("upinside", "pt_BR", "article")
    .facebook(admins=["626590460695980", "626590460695981"])
)

print(op.render())
print(op.title, op.description)

FastAPI

from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from coffeecode_optimizer import Optimizer

app = FastAPI()

@app.get("/", response_class=HTMLResponse)
def home():
    op = (
        Optimizer()
        .optimize("Title", "Desc", "https://example.com/", "https://example.com/img.jpg")
        .open_graph("example")
        .twitter_card("@me", "@me", "example.com")
    )
    return f"<!doctype html><html><head>{op.render()}</head><body><h1>{op.title}</h1></body></html>"

Flask

from flask import Flask
from coffeecode_optimizer import Optimizer

app = Flask(__name__)

@app.route("/")
def home():
    op = Optimizer().optimize("T", "D", "https://u", "https://i").open_graph("site")
    return f"<!doctype html><html><head>{op.render()}</head></html>"

API

Optimizer()

Construtor sem argumentos. Cada chamada de builder retorna self para encadeamento. Encerre com .render().

optimize(title, description, url, image, follow=True) -> Optimizer

Emite o conjunto principal: <title>, <meta name="description">, <meta name="robots">, <link rel="canonical">, bloco Open Graph, bloco Twitter Card, bloco itemprop (Schema.org).

publisher(fb_page, fb_author=None) -> Optimizer

Emite article:publisher (e opcionalmente article:author) apontando para URLs do Facebook.

open_graph(site_name, locale="pt_BR", schema="article") -> Optimizer

Emite og:type, og:site_name, og:locale. Alias openGraph mantido para compatibilidade com a API PHP.

twitter_card(creator, site, domain, card=None) -> Optimizer

Emite twitter:card (default summary_large_image), twitter:site, twitter:creator, twitter:domain. Alias twitterCard disponivel.

facebook(app_id=None, admins=None) -> Optimizer

Emite fb:app_id OU multiplas fb:admins (mutuamente exclusivos).

render() -> str

Concatena todas as tags acumuladas em uma unica string.

debug(sort=True) -> list[str]

Retorna a lista de tags ja renderizadas (uma string por tag).

data(title=None, description=None, url=None, image=None) -> SimpleNamespace

Define ou consulta o namespace de dados acessivel via op.title, op.url, etc.

Equivalencia com a versao PHP

PHP Python
CoffeeCode\Optimizer\Optimizer coffeecode_optimizer.Optimizer
CoffeeCode\Optimizer\MetaTags coffeecode_optimizer.MetaTags
optimize() optimize()
publisher() publisher()
openGraph() open_graph() (alias openGraph)
twitterCard() twitter_card() (alias twitterCard)
facebook() facebook()
render() / debug() / data() render() / debug() / data()
SimpleXMLIterator + urlencode round-trip Lista de dicts + html.escape no render

Creditos

Licenca

MIT.

Release files for coffeecode-optimizer 1.0.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 coffeecode-optimizer 1.0.0
File Size Uploaded
coffeecode_optimizer-1.0.0.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for coffeecode-optimizer 1.0.0
File Interpreter ABI Platform
coffeecode_optimizer-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.1 kB

Release files / coffeecode_optimizer-1.0.0.tar.gz

Download URL coffeecode_optimizer-1.0.0.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9851d9054b5fb05ce6190db83c7e2232f8235416628a7a3d2c34bafbe82a8ca2
BLAKE2b-256 checksum
How to use checksums
1faf3cf870995039f49c493cdbdf57020df6fd9515cf074bf05bdf82f9a47c8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 30, 2026.

Transparency log

Release files / coffeecode_optimizer-1.0.0-py3-none-any.whl

Download URL coffeecode_optimizer-1.0.0-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
004599f42e8e11bca5d10d317c53250f6723f2abc866b2368315852d3d619297
BLAKE2b-256 checksum
How to use checksums
dba11192e23186238f0aeb9c61c7eee1fbdbff8c21a3cf5e757344fb4b6b6009
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 30, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

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