|
7 | 7 | from decimal import Decimal |
8 | 8 | from typing import TYPE_CHECKING, Annotated, Literal, Protocol, TypedDict |
9 | 9 |
|
10 | | -from pydantic import BaseModel, ConfigDict, Field |
| 10 | +from pydantic import Field |
11 | 11 |
|
12 | 12 | import apify_client._models as _client_models |
13 | 13 | from apify_client._models import ActorChargeEvent as ClientActorChargeEvent |
|
28 | 28 |
|
29 | 29 | from apify._configuration import Configuration |
30 | 30 |
|
31 | | -PricingModel = Literal['PAY_PER_EVENT', 'PRICE_PER_DATASET_ITEM', 'FLAT_PRICE_PER_MONTH', 'FREE'] |
32 | | -"""Pricing model for an Actor.""" |
| 31 | +charging_manager_ctx: ContextVar[ChargingManager | None] = ContextVar('charging_manager_ctx', default=None) |
| 32 | +"""Holds the current `ChargingManager` instance, if any. |
| 33 | +
|
| 34 | +Allows PPE-aware dataset clients to access the charging manager without needing to pass it explicitly. |
| 35 | +""" |
33 | 36 |
|
34 | 37 | DEFAULT_DATASET_ITEM_EVENT = 'apify-default-dataset-item' |
| 38 | +"""Name of the synthetic event charged for each item pushed to the default dataset.""" |
35 | 39 |
|
36 | | -# Context variable to hold the current `ChargingManager` instance, if any. This allows PPE-aware dataset clients to |
37 | | -# access the charging manager without needing to pass it explicitly. |
38 | | -charging_manager_ctx: ContextVar[ChargingManager | None] = ContextVar('charging_manager_ctx', default=None) |
| 40 | +PricingModel = Literal['PAY_PER_EVENT', 'PRICE_PER_DATASET_ITEM', 'FLAT_PRICE_PER_MONTH', 'FREE'] |
| 41 | +"""Pricing model for an Actor.""" |
39 | 42 |
|
40 | 43 | _ensure_context = ensure_context('active') |
41 | 44 |
|
|
49 | 52 | # `apify-client` instance) flows through the same code paths without conversion. |
50 | 53 |
|
51 | 54 |
|
52 | | -class _RelaxedPricingMetadata(BaseModel): |
53 | | - """Mixin relaxing the `CommonActorPricingInfo` metadata fields the platform env var omits.""" |
54 | | - |
55 | | - model_config = ConfigDict(populate_by_name=True, extra='allow') |
56 | | - |
57 | | - apify_margin_percentage: Annotated[float | None, Field(alias='apifyMarginPercentage')] = None |
58 | | - created_at: Annotated[datetime | None, Field(alias='createdAt')] = None |
59 | | - started_at: Annotated[datetime | None, Field(alias='startedAt')] = None |
60 | | - |
61 | | - |
62 | 55 | @docs_group('Charging') |
63 | 56 | class ActorChargeEvent(ClientActorChargeEvent): |
64 | | - # `event_description` is required in apify-client but omitted from the env var. |
| 57 | + """Definition of a single chargeable event in the pay-per-event pricing model.""" |
| 58 | + |
65 | 59 | event_description: Annotated[str | None, Field(alias='eventDescription')] = None |
| 60 | + """Human-readable description of the event. |
| 61 | +
|
| 62 | + Required in apify-client but omitted from the env var, so it is relaxed to optional. |
| 63 | + """ |
66 | 64 |
|
67 | 65 |
|
68 | 66 | @docs_group('Charging') |
69 | 67 | class PricingPerEvent(ClientPricingPerEvent): |
| 68 | + """Pay-per-event pricing details - the chargeable events and their prices.""" |
| 69 | + |
70 | 70 | actor_charge_events: Annotated[dict[str, ActorChargeEvent] | None, Field(alias='actorChargeEvents')] = None |
| 71 | + """Mapping of event name to its charge definition.""" |
71 | 72 |
|
72 | 73 |
|
73 | 74 | @docs_group('Charging') |
74 | | -class FreeActorPricingInfo(_RelaxedPricingMetadata, ClientFree): |
75 | | - pass |
| 75 | +class FreeActorPricingInfo(ClientFree): |
| 76 | + """Pricing info for an Actor offered free of charge.""" |
| 77 | + |
| 78 | + apify_margin_percentage: Annotated[float | None, Field(alias='apifyMarginPercentage')] = None |
| 79 | + """Apify's margin on the price, as a percentage.""" |
| 80 | + |
| 81 | + created_at: Annotated[datetime | None, Field(alias='createdAt')] = None |
| 82 | + """Timestamp when this pricing info was created.""" |
| 83 | + |
| 84 | + started_at: Annotated[datetime | None, Field(alias='startedAt')] = None |
| 85 | + """Timestamp when this pricing became effective.""" |
76 | 86 |
|
77 | 87 |
|
78 | 88 | @docs_group('Charging') |
79 | | -class FlatPricePerMonthActorPricingInfo(_RelaxedPricingMetadata, ClientFlatPricePerMonth): |
| 89 | +class FlatPricePerMonthActorPricingInfo(ClientFlatPricePerMonth): |
| 90 | + """Pricing info for an Actor billed at a flat monthly price.""" |
| 91 | + |
| 92 | + apify_margin_percentage: Annotated[float | None, Field(alias='apifyMarginPercentage')] = None |
| 93 | + """Apify's margin on the price, as a percentage.""" |
| 94 | + |
| 95 | + created_at: Annotated[datetime | None, Field(alias='createdAt')] = None |
| 96 | + """Timestamp when this pricing info was created.""" |
| 97 | + |
| 98 | + started_at: Annotated[datetime | None, Field(alias='startedAt')] = None |
| 99 | + """Timestamp when this pricing became effective.""" |
| 100 | + |
80 | 101 | trial_minutes: Annotated[int | None, Field(alias='trialMinutes')] = None |
| 102 | + """Length of the free trial period, in minutes.""" |
| 103 | + |
81 | 104 | price_per_unit_usd: Annotated[float | None, Field(alias='pricePerUnitUsd')] = None |
| 105 | + """Price per unit, in USD.""" |
82 | 106 |
|
83 | 107 |
|
84 | 108 | @docs_group('Charging') |
85 | | -class PricePerDatasetItemActorPricingInfo(_RelaxedPricingMetadata, ClientPricePerDatasetItem): |
| 109 | +class PricePerDatasetItemActorPricingInfo(ClientPricePerDatasetItem): |
| 110 | + """Pricing info for an Actor billed per dataset item produced.""" |
| 111 | + |
| 112 | + apify_margin_percentage: Annotated[float | None, Field(alias='apifyMarginPercentage')] = None |
| 113 | + """Apify's margin on the price, as a percentage.""" |
| 114 | + |
| 115 | + created_at: Annotated[datetime | None, Field(alias='createdAt')] = None |
| 116 | + """Timestamp when this pricing info was created.""" |
| 117 | + |
| 118 | + started_at: Annotated[datetime | None, Field(alias='startedAt')] = None |
| 119 | + """Timestamp when this pricing became effective.""" |
| 120 | + |
86 | 121 | unit_name: Annotated[str | None, Field(alias='unitName')] = None |
87 | | - # `price_per_unit_usd` is already optional in apify-client - inherited. |
| 122 | + """Name of the billed unit.""" |
88 | 123 |
|
89 | 124 |
|
90 | 125 | @docs_group('Charging') |
91 | | -class PayPerEventActorPricingInfo(_RelaxedPricingMetadata, ClientPayPerEvent): |
92 | | - # Re-typed to the relaxed element so an omitted `eventDescription` validates; the field stays required. |
| 126 | +class PayPerEventActorPricingInfo(ClientPayPerEvent): |
| 127 | + """Pricing info for an Actor billed per charged event.""" |
| 128 | + |
| 129 | + apify_margin_percentage: Annotated[float | None, Field(alias='apifyMarginPercentage')] = None |
| 130 | + """Apify's margin on the price, as a percentage.""" |
| 131 | + |
| 132 | + created_at: Annotated[datetime | None, Field(alias='createdAt')] = None |
| 133 | + """Timestamp when this pricing info was created.""" |
| 134 | + |
| 135 | + started_at: Annotated[datetime | None, Field(alias='startedAt')] = None |
| 136 | + """Timestamp when this pricing became effective.""" |
| 137 | + |
93 | 138 | pricing_per_event: Annotated[PricingPerEvent, Field(alias='pricingPerEvent')] |
| 139 | + """The pay-per-event pricing details.""" |
94 | 140 |
|
95 | 141 |
|
96 | 142 | ActorPricingInfoModel = ClientFree | ClientFlatPricePerMonth | ClientPricePerDatasetItem | ClientPayPerEvent |
|
0 commit comments