SEO meta tag and social sharing tag generator (OpenGraph, Twitter Card, Facebook). Python fork of robsonvleite/optimizer (PHP).
Project description
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
- API original: Robson V. Leite — coffeecode/optimizer (MIT)
- Port Python: Kaue Leal
Licenca
MIT.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file coffeecode_optimizer-1.0.0.tar.gz.
File metadata
- Download URL: coffeecode_optimizer-1.0.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9851d9054b5fb05ce6190db83c7e2232f8235416628a7a3d2c34bafbe82a8ca2
|
|
| MD5 |
3cff63daf6a6e5a32a7308f3fd908130
|
|
| BLAKE2b-256 |
1faf3cf870995039f49c493cdbdf57020df6fd9515cf074bf05bdf82f9a47c8e
|
Provenance
The following attestation bundles were made for coffeecode_optimizer-1.0.0.tar.gz:
Publisher:
release.yml on kauelima21/coffeecode-optimizer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
coffeecode_optimizer-1.0.0.tar.gz -
Subject digest:
9851d9054b5fb05ce6190db83c7e2232f8235416628a7a3d2c34bafbe82a8ca2 - Sigstore transparency entry: 1414872833
- Sigstore integration time:
-
Permalink:
kauelima21/coffeecode-optimizer@a7c0fac05941a33044f84b11f6952847a1c6714d -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/kauelima21
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a7c0fac05941a33044f84b11f6952847a1c6714d -
Trigger Event:
push
-
Statement type:
File details
Details for the file coffeecode_optimizer-1.0.0-py3-none-any.whl.
File metadata
- Download URL: coffeecode_optimizer-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
004599f42e8e11bca5d10d317c53250f6723f2abc866b2368315852d3d619297
|
|
| MD5 |
fc5ce2acc250dc29dcaf992670b2ec1e
|
|
| BLAKE2b-256 |
dba11192e23186238f0aeb9c61c7eee1fbdbff8c21a3cf5e757344fb4b6b6009
|
Provenance
The following attestation bundles were made for coffeecode_optimizer-1.0.0-py3-none-any.whl:
Publisher:
release.yml on kauelima21/coffeecode-optimizer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
coffeecode_optimizer-1.0.0-py3-none-any.whl -
Subject digest:
004599f42e8e11bca5d10d317c53250f6723f2abc866b2368315852d3d619297 - Sigstore transparency entry: 1414872911
- Sigstore integration time:
-
Permalink:
kauelima21/coffeecode-optimizer@a7c0fac05941a33044f84b11f6952847a1c6714d -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/kauelima21
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a7c0fac05941a33044f84b11f6952847a1c6714d -
Trigger Event:
push
-
Statement type: