flet-ads 0.1.0.dev2__py3-none-any.whl → 0.2.0.dev37__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of flet-ads might be problematic. Click here for more details.

flet_ads/__init__.py CHANGED
@@ -1,10 +1,10 @@
1
- from flet_ads.banner import BannerAd
2
- from flet_ads.interstitial import InterstitialAd
1
+ from .banner_ad import BannerAd
2
+ from .base_ad import BaseAd
3
+ from .interstitial_ad import InterstitialAd
4
+ from .types import ( # NativeAdTemplateStyle,; NativeAdTemplateTextStyle,; NativeAdTemplateType,; NativeTemplateFontStyle,
5
+ AdRequest,
6
+ PaidAdEvent,
7
+ PrecisionType,
8
+ )
3
9
 
4
- # from flet_ads.native import (
5
- # NativeAd,
6
- # NativeAdTemplateStyle,
7
- # NativeAdTemplateTextStyle,
8
- # NativeAdTemplateType,
9
- # NativeTemplateFontStyle,
10
- # )
10
+ # from .native_ad import NativeAd
flet_ads/banner_ad.py ADDED
@@ -0,0 +1,29 @@
1
+ import flet as ft
2
+
3
+ from .base_ad import BaseAd
4
+ from .types import PaidAdEvent
5
+
6
+
7
+ @ft.control("BannerAd")
8
+ class BannerAd(BaseAd):
9
+ """
10
+ Displays a banner ad.
11
+
12
+ Raises:
13
+ AssertionError: When using this control on a web and/or non-mobile platform.
14
+ """
15
+
16
+ on_will_dismiss: ft.OptionalControlEventHandler["BannerAd"] = None
17
+ """
18
+ Called before dismissing a full screen view.
19
+
20
+ Note:
21
+ Only available on iOS.
22
+ """
23
+
24
+ on_paid: ft.OptionalControlEventHandler[PaidAdEvent["BannerAd"]] = None
25
+ """
26
+ Called when this ad is estimated to have earned money.
27
+
28
+ Available for allowlisted accounts only.
29
+ """
flet_ads/base_ad.py CHANGED
@@ -1,174 +1,67 @@
1
- from typing import Any, Optional, Union
2
-
3
- from flet.core.animation import AnimationValue
4
- from flet.core.constrained_control import ConstrainedControl
5
- from flet.core.control import OptionalNumber
6
- from flet.core.ref import Ref
7
- from flet.core.types import (
8
- OffsetValue,
9
- OptionalControlEventCallable,
10
- PagePlatform,
11
- ResponsiveNumber,
12
- RotateValue,
13
- ScaleValue,
14
- )
15
-
16
-
17
- class BaseAd(ConstrainedControl):
18
- def __init__(
19
- self,
20
- unit_id: str,
21
- on_load: OptionalControlEventCallable = None,
22
- on_error: OptionalControlEventCallable = None,
23
- on_open: OptionalControlEventCallable = None,
24
- on_close: OptionalControlEventCallable = None,
25
- on_impression: OptionalControlEventCallable = None,
26
- on_click: OptionalControlEventCallable = None,
27
- on_will_dismiss: OptionalControlEventCallable = None,
28
- #
29
- # ConstrainedControl
30
- #
31
- ref: Optional[Ref] = None,
32
- key: Optional[str] = None,
33
- width: OptionalNumber = None,
34
- height: OptionalNumber = None,
35
- left: OptionalNumber = None,
36
- top: OptionalNumber = None,
37
- right: OptionalNumber = None,
38
- bottom: OptionalNumber = None,
39
- expand: Union[None, bool, int] = None,
40
- expand_loose: Optional[bool] = None,
41
- col: Optional[ResponsiveNumber] = None,
42
- opacity: OptionalNumber = None,
43
- rotate: RotateValue = None,
44
- scale: ScaleValue = None,
45
- offset: OffsetValue = None,
46
- aspect_ratio: OptionalNumber = None,
47
- animate_opacity: AnimationValue = None,
48
- animate_size: AnimationValue = None,
49
- animate_position: AnimationValue = None,
50
- animate_rotation: AnimationValue = None,
51
- animate_scale: AnimationValue = None,
52
- animate_offset: AnimationValue = None,
53
- on_animation_end: OptionalControlEventCallable = None,
54
- tooltip: Optional[str] = None,
55
- visible: Optional[bool] = None,
56
- disabled: Optional[bool] = None,
57
- data: Any = None,
58
- ):
59
- ConstrainedControl.__init__(
60
- self,
61
- ref=ref,
62
- key=key,
63
- width=width,
64
- height=height,
65
- left=left,
66
- top=top,
67
- right=right,
68
- bottom=bottom,
69
- expand=expand,
70
- expand_loose=expand_loose,
71
- col=col,
72
- opacity=opacity,
73
- rotate=rotate,
74
- scale=scale,
75
- offset=offset,
76
- aspect_ratio=aspect_ratio,
77
- animate_opacity=animate_opacity,
78
- animate_size=animate_size,
79
- animate_position=animate_position,
80
- animate_rotation=animate_rotation,
81
- animate_scale=animate_scale,
82
- animate_offset=animate_offset,
83
- on_animation_end=on_animation_end,
84
- tooltip=tooltip,
85
- visible=visible,
86
- disabled=disabled,
87
- data=data,
88
- )
89
-
90
- self.on_load = on_load
91
- self.on_error = on_error
92
- self.on_open = on_open
93
- self.on_close = on_close
94
- self.on_impression = on_impression
95
- self.on_click = on_click
96
- self.on_will_dismiss = on_will_dismiss
97
- self.unit_id = unit_id
1
+ from dataclasses import field
2
+
3
+ import flet as ft
4
+
5
+ from flet_ads.types import AdRequest
6
+
7
+
8
+ @ft.control
9
+ class BaseAd(ft.Control):
10
+ """
11
+ Base class for all ad controls in Flet Ads package.
12
+
13
+ Raises:
14
+ AssertionError: When using this control on a web and/or non-mobile platform.
15
+ """
16
+
17
+ unit_id: str
18
+ """
19
+ Ad unit ID for this ad.
20
+ """
21
+
22
+ request: AdRequest = field(default_factory=lambda: AdRequest())
23
+ """
24
+ Targeting information used to fetch an Ad.
25
+ """
26
+
27
+ on_load: ft.OptionalControlEventHandler["BaseAd"] = None
28
+ """
29
+ Called when this ad is loaded successfully.
30
+ """
31
+
32
+ on_error: ft.OptionalControlEventHandler["BaseAd"] = None
33
+ """
34
+ Called when an ad request failed.
35
+
36
+ Event handler argument `data` property contains information about the error.
37
+ """
38
+
39
+ on_open: ft.OptionalControlEventHandler["BaseAd"] = None
40
+ """
41
+ Called when this ad opens up.
42
+
43
+ A full screen view/overlay is presented in response to the user clicking
44
+ on an ad. You may want to pause animations and time sensitive
45
+ interactions.
46
+ """
47
+
48
+ on_close: ft.OptionalControlEventHandler["BaseAd"] = None
49
+ """
50
+ Called when the full screen view has been closed. You should restart
51
+ anything paused while handling [`on_open`][..].
52
+ """
53
+
54
+ on_impression: ft.OptionalControlEventHandler["BaseAd"] = None
55
+ """
56
+ Called when an impression occurs on this ad.
57
+ """
58
+
59
+ on_click: ft.OptionalControlEventHandler["BaseAd"] = None
60
+ """
61
+ Called when this ad is clicked.
62
+ """
98
63
 
99
64
  def before_update(self):
100
- assert self.page.platform in [
101
- PagePlatform.ANDROID,
102
- PagePlatform.IOS,
103
- ], f"{self.__class__.__name__} is only supported on Mobile (Android and iOS). "
104
-
105
- @property
106
- def unit_id(self) -> str:
107
- return self._get_attr("unitId")
108
-
109
- @unit_id.setter
110
- def unit_id(self, value: str):
111
- self._set_attr("unitId", value)
112
-
113
- # on_load
114
- @property
115
- def on_load(self):
116
- return self._get_event_handler("load")
117
-
118
- @on_load.setter
119
- def on_load(self, handler):
120
- self._add_event_handler("load", handler)
121
-
122
- # on_error
123
- @property
124
- def on_error(self):
125
- return self._get_event_handler("error")
126
-
127
- @on_error.setter
128
- def on_error(self, handler):
129
- self._add_event_handler("error", handler)
130
-
131
- # on_open
132
- @property
133
- def on_open(self):
134
- return self._get_event_handler("open")
135
-
136
- @on_open.setter
137
- def on_open(self, handler):
138
- self._add_event_handler("open", handler)
139
-
140
- # on_close
141
- @property
142
- def on_close(self):
143
- return self._get_event_handler("close")
144
-
145
- @on_close.setter
146
- def on_close(self, handler):
147
- self._add_event_handler("close", handler)
148
-
149
- # on_click
150
- @property
151
- def on_click(self):
152
- return self._get_event_handler("click")
153
-
154
- @on_click.setter
155
- def on_click(self, handler):
156
- self._add_event_handler("click", handler)
157
-
158
- # on_impression
159
- @property
160
- def on_impression(self):
161
- return self._get_event_handler("impression")
162
-
163
- @on_impression.setter
164
- def on_impression(self, handler):
165
- self._add_event_handler("impression", handler)
166
-
167
- # on_will_dismiss
168
- @property
169
- def on_will_dismiss(self):
170
- return self._get_event_handler("willDismiss")
171
-
172
- @on_will_dismiss.setter
173
- def on_will_dismiss(self, handler):
174
- self._add_event_handler("willDismiss", handler)
65
+ assert (
66
+ not self.page.web and self.page.platform.is_mobile()
67
+ ), f"{self.__class__.__name__} is only supported on Mobile (Android and iOS)"
@@ -0,0 +1,21 @@
1
+ import asyncio
2
+
3
+ import flet as ft
4
+
5
+ from .base_ad import BaseAd
6
+
7
+
8
+ @ft.control("InterstitialAd")
9
+ class InterstitialAd(BaseAd):
10
+ """
11
+ Displays a full-screen interstitial ad.
12
+
13
+ Raises:
14
+ AssertionError: When using this control on a web and/or non-mobile platform.
15
+ """
16
+
17
+ def show(self):
18
+ asyncio.create_task(self.show_async())
19
+
20
+ async def show_async(self):
21
+ await self._invoke_method_async("show")
flet_ads/native_ad.py ADDED
@@ -0,0 +1,32 @@
1
+ import flet as ft
2
+
3
+ from .banner_ad import BannerAd
4
+ from .types import NativeAdTemplateStyle
5
+
6
+ __all__ = ["NativeAd"]
7
+
8
+
9
+ @ft.control("NativeAd")
10
+ class NativeAd(BannerAd):
11
+ """
12
+ Renders a native ad.
13
+
14
+ Raises:
15
+ AssertionError: When neither [`factory_id`][..] nor [`template_style`][..] is set.
16
+ """
17
+
18
+ factory_id: str = None
19
+ """
20
+ An identifier for the factory that creates the Platform view.
21
+ """
22
+
23
+ template_style: NativeAdTemplateStyle = None
24
+ """
25
+ A style for the native ad template.
26
+ """
27
+
28
+ def before_update(self):
29
+ super().before_update()
30
+ assert (
31
+ self.factory_id is not None or self.template_style is not None
32
+ ), "factory_id or template_style must be set"
flet_ads/types.py ADDED
@@ -0,0 +1,129 @@
1
+ from dataclasses import dataclass
2
+ from enum import Enum
3
+ from typing import Optional
4
+
5
+ import flet as ft
6
+
7
+ __all__ = [
8
+ "PrecisionType",
9
+ "PaidAdEvent",
10
+ "AdRequest",
11
+ "NativeAdTemplateType",
12
+ "NativeTemplateFontStyle",
13
+ "NativeAdTemplateTextStyle",
14
+ "NativeAdTemplateStyle",
15
+ ]
16
+
17
+
18
+ class PrecisionType(Enum):
19
+ UNKNOWN = "unknown"
20
+ """An ad value with unknown precision."""
21
+
22
+ ESTIMATED = "estimated"
23
+ """An ad value estimated from aggregated data."""
24
+
25
+ PUBLISHER_PROVIDED = "publisherProvided"
26
+ """A publisher-provided ad value, such as manual CPMs in a mediation group."""
27
+
28
+ PRECISE = "precise"
29
+ """The precise value paid for this ad."""
30
+
31
+
32
+ @dataclass
33
+ class PaidAdEvent(ft.Event[ft.EventControlType]):
34
+ """
35
+ Event data for paid ad events.
36
+ """
37
+
38
+ value: float
39
+ """
40
+ The monetary value of the ad.
41
+ """
42
+
43
+ precision: PrecisionType
44
+ """
45
+ The precision of the ad value.
46
+ """
47
+
48
+ currency_code: str
49
+ """
50
+ The currency code of the ad value.
51
+ """
52
+
53
+
54
+ @dataclass
55
+ class AdRequest:
56
+ """
57
+ Targeting info per the AdMob API.
58
+
59
+ This class's properties mirror the native AdRequest API. See for example:
60
+ [AdRequest.Builder for Android](https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest.Builder).
61
+ """
62
+
63
+ keywords: Optional[list[str]] = None
64
+ """
65
+ Words or phrases describing the current user activity.
66
+ """
67
+
68
+ content_url: Optional[str] = None
69
+ """
70
+ URL string for a webpage whose content matches the app’s primary content.
71
+
72
+ This webpage content is used for targeting and brand safety purposes.
73
+ """
74
+
75
+ neighboring_content_urls: Optional[list[str]] = None
76
+ """
77
+ URLs representing web content near an ad.
78
+ """
79
+
80
+ non_personalized_ads: Optional[bool] = None
81
+ """
82
+ Non-personalized ads are ads that are not based on a user’s past behavior.
83
+
84
+ For more information: https://support.google.com/admob/answer/7676680?hl=en
85
+ """
86
+
87
+ http_timeout: Optional[int] = None
88
+ """
89
+ A custom timeout (in milliseconds) for HTTPS calls during an ad request.
90
+
91
+ Note:
92
+ This is only supported in Android. (ignored on iOS)
93
+ """
94
+
95
+ extras: Optional[dict[str, str]] = None
96
+ """
97
+ Extras to pass to the AdMob adapter.
98
+ """
99
+
100
+
101
+ class NativeAdTemplateType(Enum):
102
+ SMALL = "small"
103
+ MEDIUM = "medium"
104
+
105
+
106
+ class NativeTemplateFontStyle(Enum):
107
+ NORMAL = "normal"
108
+ BOLD = "bold"
109
+ ITALIC = "italic"
110
+ MONOSPACE = "monospace"
111
+
112
+
113
+ @dataclass
114
+ class NativeAdTemplateTextStyle:
115
+ size: Optional[ft.Number] = None
116
+ text_color: Optional[ft.ColorValue] = None
117
+ bgcolor: Optional[ft.ColorValue] = None
118
+ style: Optional[NativeTemplateFontStyle] = None
119
+
120
+
121
+ @dataclass
122
+ class NativeAdTemplateStyle:
123
+ template_type: NativeAdTemplateType = NativeAdTemplateType.MEDIUM
124
+ main_bgcolor: Optional[ft.ColorValue] = None
125
+ corner_radius: Optional[ft.Number] = None
126
+ call_to_action_text_style: Optional[NativeAdTemplateTextStyle] = None
127
+ primary_text_style: Optional[NativeAdTemplateTextStyle] = None
128
+ secondary_text_style: Optional[NativeAdTemplateTextStyle] = None
129
+ tertiary_text_style: Optional[NativeAdTemplateTextStyle] = None
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.4
2
+ Name: flet-ads
3
+ Version: 0.2.0.dev37
4
+ Summary: Display Google Ads in Flet apps.
5
+ Author-email: Flet contributors <hello@flet.dev>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://flet.dev
8
+ Project-URL: Documentation, https://flet-dev.github.io/flet-ads
9
+ Project-URL: Repository, https://github.com/flet-dev/flet-ads
10
+ Project-URL: Issues, https://github.com/flet-dev/flet-ads/issues
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: flet>=0.70.0.dev0
15
+ Dynamic: license-file
16
+
17
+ # flet-ads
18
+
19
+ [![pypi](https://img.shields.io/pypi/v/flet-ads.svg)](https://pypi.python.org/pypi/flet-ads)
20
+ [![downloads](https://static.pepy.tech/badge/flet-ads/month)](https://pepy.tech/project/flet-ads)
21
+ [![license](https://img.shields.io/github/license/flet-dev/flet-ads.svg)](https://github.com/flet-dev/flet-ads/blob/main/LICENSE)
22
+
23
+ Display Google Ads in [Flet](https://flet.dev) apps.
24
+
25
+ It is based on the [google_mobile_ads](https://pub.dev/packages/google_mobile_ads) Flutter package.
26
+
27
+ ## Documentation
28
+
29
+ Detailed documentation to this package can be found [here](https://flet-dev.github.io/flet-ads/).
30
+
31
+ ## Platform Support
32
+
33
+ This package supports the following platforms:
34
+
35
+ | Platform | Supported |
36
+ |----------|:---------:|
37
+ | Windows | ❌ |
38
+ | macOS | ❌ |
39
+ | Linux | ❌ |
40
+ | iOS | ✅ |
41
+ | Android | ✅ |
42
+ | Web | ❌ |
43
+
44
+ ## Installation
45
+
46
+ To install the `flet-ads` package and add it to your project dependencies:
47
+
48
+ - Using `uv`:
49
+ ```bash
50
+ uv add flet-ads
51
+ ```
52
+
53
+ - Using `pip`:
54
+ ```bash
55
+ pip install flet-ads
56
+ ```
57
+ After this, you will have to manually add this package to your `requirements.txt` or `pyproject.toml`.
58
+
59
+ - Using `poetry`:
60
+ ```bash
61
+ poetry add flet-ads
62
+ ```
63
+
64
+ ## Examples
65
+
66
+ For examples, see [this](./examples)
@@ -0,0 +1,11 @@
1
+ flet_ads/__init__.py,sha256=IJRqRlozCGkISTdcXX7xn7-jzUtp1yMp6y2msgpPR6g,316
2
+ flet_ads/banner_ad.py,sha256=esnqiKAmeaLEpBSJfO1_z847FyKvTrtk3YypjRh8d0U,645
3
+ flet_ads/base_ad.py,sha256=lYuEWwYVVd1qTmVFt02igcAS-g6tOcFzwbO4Li18mY0,1748
4
+ flet_ads/interstitial_ad.py,sha256=KXGcf0bXIDDw4gPeo4O0vR3LK9wgRSa6gAzxPl40qNg,432
5
+ flet_ads/native_ad.py,sha256=-4xOvEjaIWCWSQbgPX1JBpqOTBARN-cwaPPTPuQxCrQ,737
6
+ flet_ads/types.py,sha256=q1Hpmu_w6afkG6ovLUgToWSRVb1Euf-OVlf52si00VM,3212
7
+ flet_ads-0.2.0.dev37.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
8
+ flet_ads-0.2.0.dev37.dist-info/METADATA,sha256=dgXnm-O3WNEdG48xDiOURgwH5HiYmR7-uEo07l-ldhs,1870
9
+ flet_ads-0.2.0.dev37.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
10
+ flet_ads-0.2.0.dev37.dist-info/top_level.txt,sha256=gv6ICx8xIfzUQalF99v9x0gh0g0R8EPksQFAknB3baM,9
11
+ flet_ads-0.2.0.dev37.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -198,4 +198,4 @@
198
198
  distributed under the License is distributed on an "AS IS" BASIS,
199
199
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
200
  See the License for the specific language governing permissions and
201
- limitations under the License.
201
+ limitations under the License.
flet_ads/banner.py DELETED
@@ -1,110 +0,0 @@
1
- from typing import Any, Optional, Union
2
-
3
- from flet.core.animation import AnimationValue
4
- from flet.core.control import OptionalNumber
5
- from flet.core.ref import Ref
6
- from flet.core.types import (
7
- OffsetValue,
8
- OptionalControlEventCallable,
9
- ResponsiveNumber,
10
- RotateValue,
11
- ScaleValue,
12
- )
13
-
14
- from flet_ads.base_ad import BaseAd
15
-
16
-
17
- class BannerAd(BaseAd):
18
- """
19
- Displays a banner ad.
20
-
21
- -----
22
-
23
- Online docs: https://flet.dev/docs/controls/bannerad
24
- """
25
-
26
- def __init__(
27
- self,
28
- unit_id: str,
29
- on_load: OptionalControlEventCallable = None,
30
- on_error: OptionalControlEventCallable = None,
31
- on_open: OptionalControlEventCallable = None,
32
- on_close: OptionalControlEventCallable = None,
33
- on_impression: OptionalControlEventCallable = None,
34
- on_click: OptionalControlEventCallable = None,
35
- on_will_dismiss: OptionalControlEventCallable = None,
36
- #
37
- # ConstrainedControl
38
- #
39
- ref: Optional[Ref] = None,
40
- key: Optional[str] = None,
41
- width: OptionalNumber = None,
42
- height: OptionalNumber = None,
43
- left: OptionalNumber = None,
44
- top: OptionalNumber = None,
45
- right: OptionalNumber = None,
46
- bottom: OptionalNumber = None,
47
- expand: Union[None, bool, int] = None,
48
- expand_loose: Optional[bool] = None,
49
- col: Optional[ResponsiveNumber] = None,
50
- opacity: OptionalNumber = None,
51
- rotate: RotateValue = None,
52
- scale: ScaleValue = None,
53
- offset: OffsetValue = None,
54
- aspect_ratio: OptionalNumber = None,
55
- animate_opacity: AnimationValue = None,
56
- animate_size: AnimationValue = None,
57
- animate_position: AnimationValue = None,
58
- animate_rotation: AnimationValue = None,
59
- animate_scale: AnimationValue = None,
60
- animate_offset: AnimationValue = None,
61
- on_animation_end: OptionalControlEventCallable = None,
62
- tooltip: Optional[str] = None,
63
- visible: Optional[bool] = None,
64
- disabled: Optional[bool] = None,
65
- data: Any = None,
66
- ):
67
- BaseAd.__init__(
68
- self,
69
- unit_id=unit_id,
70
- on_load=on_load,
71
- on_error=on_error,
72
- on_open=on_open,
73
- on_close=on_close,
74
- on_impression=on_impression,
75
- on_click=on_click,
76
- on_will_dismiss=on_will_dismiss,
77
- #
78
- # ConstrainedControl
79
- #
80
- ref=ref,
81
- key=key,
82
- width=width,
83
- height=height,
84
- left=left,
85
- top=top,
86
- right=right,
87
- bottom=bottom,
88
- expand=expand,
89
- expand_loose=expand_loose,
90
- col=col,
91
- opacity=opacity,
92
- rotate=rotate,
93
- scale=scale,
94
- offset=offset,
95
- aspect_ratio=aspect_ratio,
96
- animate_opacity=animate_opacity,
97
- animate_size=animate_size,
98
- animate_position=animate_position,
99
- animate_rotation=animate_rotation,
100
- animate_scale=animate_scale,
101
- animate_offset=animate_offset,
102
- on_animation_end=on_animation_end,
103
- tooltip=tooltip,
104
- visible=visible,
105
- disabled=disabled,
106
- data=data,
107
- )
108
-
109
- def _get_control_name(self):
110
- return "banner_ad"