flayyer-python
The AI-powered preview system built from your website (no effort required).
This module is agnostic to any Python framework.
Index
Get started (5 minutes)
Haven't registered your website yet? Go to Flayyer.com and create a project (e.g. website-com).
1. Install the library
This module requires Python >= 3.6.
Install it with Poetry.
poetry add flayyer
Or install it with pip.
pip install flayyer
2. Get your Flayyer.ai smart image link
In your website code (e.g. your landing or product/post view file), set the following:
from flayyer import FlayyerAI
flayyer = FlayyerAI(
# Your project slug
project="website-com",
# The current path of your website
path="/path/to/product", # In Django you can use {{ request.get_full_path }}
)
# Check:
print(flayyer.href())
# > https://flayyer.ai/v2/website-com/_/__v=1618281823/path/to/product
3. Put your smart image link in your <head> tags
You'll get the best results like this:
<meta property="og:image" content="{{ flayyer.href() }}">
<meta name="twitter:image" content="{{ flayyer.href() }}">
<meta name="twitter:card" content="summary_large_image">
4. Create a rule for your project
Login at Flayyer.com > Go to your Dashboard > Manage rules and create a rule like the following:
Voilà!
Advanced usage
Advanced features include:
- Custom variables: additional information for your preview that is not present in your website. [Note: if you need customization you should take a look at Flayyer.io]
- Custom metadata: set custom width, height, resolution, and more (see example).
- Signed URLs.
Here you have a detailed full example for project website-com and path /path/to/product.
from flayyer import FlayyerAI, FlayyerMeta
flayyer = FlayyerAI(
# [Required] Your project slug, find it in your dashboard https://flayyer.com/dashboard/.
project="website-com",
# [Recommended] The current path of your website (by default it's `/`).
path="/path/to/product",
# [Optional] In case you want to provide information that is not present in your page set it here.
variables={
"title": "Product name",
"img": "https://flayyer.com/img/marketplace/flayyer-banner.png",
},
# [Optional] Custom metadata for rendering the image. ID is recommended so we provide you with better statistics.
meta=FlayyerMeta(
id="jeans-123", # recommended for better stats
v="12369420123", # specific handler version, by default it's a random number to circumvent platforms' cache,
width=1200,
height=600,
resolution=0.9, # from 0.0 to 1.0
agent="whatsapp", # force dimensions for specific platform
),
)
# Check:
print(flayyer.href())
# > https://flayyer.ai/v2/website-com/_/__v=1618281823/path/to/product
For signed URLs, just provide your secret (find it in Dashboard > Project > Advanced settings) and choose a strategy (HMAC or JWT).
flayyer = FlayyerAI(
project="website-com",
path="/path/to/product",
secret="your-secret-key",
strategy="JWT", # or 'HMAC'
)
print(flayyer.href())
# > https://flayyer.ai/v2/website-com/jwt-eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXJhbXMiOnsiX19pZCI6ImplYW5zLTEyMyJ9LCJwYXRoIjoiXC9wYXRoXC90b1wvcHJvZHVjdCJ9.X8Vs5SGEA1-3M6bH-h24jhQnbwH95V_G0f-gPhTBTzE?__v=1618283086
Flayyer.io
As you probably realized, Flayyer.ai uses the rules defined on your dashboard to decide how to handle every image based on path patterns. It fetches and analyse your website for obtaining information and then rendering a content-rich image increasing the click-through-rate with no effort. Let's say "FlayyerAI render images based on the content of this route".
Flayyer.io instead requires you to explicitly declare template and variables for the images to render, giving you more control for customization. Let's say "FlayyerIO render an image using this template and these explicit variables".
from flayyer import Flayyer
flayyer = Flayyer(
tenant="tenant",
deck="deck",
template="template",
variables={"title": "Hello world!"},
)
# Use this image in your <head/> tags
url = flayyer.href()
# > https://flayyer.io/v2/tenant/deck/template.jpeg?__v=1596906866&title=Hello+world%21
Variables can be complex arrays and hashes.
from flayyer import Flayyer, FlayyerMeta
flayyer = Flayyer(
tenant="tenant",
deck="deck",
template="template",
variables={
"items": [
{ "text": "Oranges", "count": 12 },
{ "text": "Apples", "count": 14 },
],
},
meta=FlayyerMeta(
id="slug-or-id", # To identify the resource in our analytics report
),
)
IMPORTANT: variables must be serializable.
To decode the URL for debugging purposes:
from urllib.parse import unquote
print(unquote(url))
# > https://flayyer.io/v2/tenant/deck/template.jpeg?title=Hello+world!&__v=123
Development
Prepare the local environment:
poetry install
poetry shell
Deploy with:
# Set API Token
poetry config pypi-token.pypi pypi-TOKEN
poetry version X.Y.Z
poetry build
poetry publish
Test
Run tests with pytest:
poetry run pytest
Run black linter:
black .
Metadata
Release files for flayyer 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| flayyer-1.2.0.tar.gz | 6.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flayyer-1.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.5 kB
Release files / flayyer-1.2.0.tar.gz
| Download URL | flayyer-1.2.0.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0bc9f8f9a508b1f2797446406c0964c17e978e671087f31611c21658af6c0649
|
|
BLAKE2b-256 checksum How to use checksums |
8817f1bb3657fd8e3eceda87115c4f07a6591ec41c926032ea1a43767f320a01
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.5 CPython/3.9.2 Darwin/19.6.0
|
Release files / flayyer-1.2.0-py3-none-any.whl
| Download URL | flayyer-1.2.0-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b6b505514b2b132c51e4f04a9095dcd8f83f5a8f013947e85ab664ba0c193c34
|
|
BLAKE2b-256 checksum How to use checksums |
52df10c5895720bb424c537ed76e5884c7cff11e7f0f8dfc7f57bcec517b265b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.5 CPython/3.9.2 Darwin/19.6.0
|
Security for flayyer 1.2.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.