cavlyn 1.0.0__tar.gz

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.
cavlyn-1.0.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
cavlyn-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,243 @@
1
+ Metadata-Version: 2.4
2
+ Name: cavlyn
3
+ Version: 1.0.0
4
+ Summary: Official Python server SDK for Cavlyn: generate dynamic links, parse/resolve deep links, configure multi-platform routing, and ingest server events.
5
+ Author-email: Cavlyn System <dev@cavlyn.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/casontek/smart-attribution-system/tree/main/sdk/python
8
+ Project-URL: Repository, https://github.com/casontek/smart-attribution-system
9
+ Project-URL: Issues, https://github.com/casontek/smart-attribution-system/issues
10
+ Project-URL: Documentation, https://docs.cavlyn.com
11
+ Keywords: dynamic-links,deep-linking,deferred-deep-linking,attribution,smart-links,url-shortener,mobile-attribution
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Requires-Python: >=3.9
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Dynamic: license-file
25
+
26
+ # Cavlyn Python Server SDK
27
+
28
+ Official server-side Python library for Cavlyn. Create and manage intelligent dynamic deep links and UTM campaigns, parse/resolve deep links, configure multi-platform routing, and ingest server-side conversion events.
29
+
30
+ ## Features
31
+
32
+ - **Programmatic Dynamic Deep Link CRUD**: Create, list, inspect, update, and delete branded short links from backend services, Celery jobs, transactional emails, or Django/FastAPI applications.
33
+ - **Programmatic Campaign Creation & Querying**: Create and list UTM attribution campaigns and attach `campaign_id` directly to dynamic links.
34
+ - **Automatic App Scoping**: `app_id` is inferred automatically from your `X-API-Key` when omitted.
35
+ - **Deep links for mobile apps**: Links open your app through Universal Links and App Links. What happens when the app isn't installed (App Store, Play Store or web) is configured per app in the Cavlyn dashboard, not per link.
36
+ - **Dynamic Link Parsing & Resolution**: Decode short codes or full dynamic link URLs into structured data, parameters, and campaign tokens.
37
+ - **Open Graph Preview Customizer**: Attach custom social share preview cards for WhatsApp, iMessage, Twitter, and Slack.
38
+ - **Zero Heavy Dependencies**: Built with pure Python standard library (`urllib`, `dataclasses`, `json`), ensuring zero package conflicts in your environment.
39
+
40
+ ---
41
+
42
+ ## Installation
43
+
44
+ ```bash
45
+ pip install cavlyn
46
+ ```
47
+
48
+ *(Or copy `cavlyn/` directly into your Python project)*
49
+
50
+ ---
51
+
52
+ ## Quickstart
53
+
54
+ ### 1. Initialize Client
55
+
56
+ ```python
57
+ import os
58
+ from cavlyn import CavlynClient
59
+
60
+ client = CavlynClient(
61
+ api_key=os.environ["CAVLYN_API_KEY"],
62
+ base_url="https://api.cavlyn.com", # default; use "http://localhost:8080" for local development
63
+ link_domain="https://link.yourdomain.com", # Branded short link domain used to build link.url
64
+ # timeout=30.0, # seconds
65
+ # default_app_id is optional — inferred automatically from X-API-Key
66
+ )
67
+ ```
68
+
69
+ ---
70
+
71
+ ### 2. Create & List UTM Campaigns
72
+
73
+ ```python
74
+ campaign = client.create_campaign(
75
+ name="Summer Drop 2026",
76
+ source="newsletter",
77
+ medium="email",
78
+ campaign="summer_drop",
79
+ starts_at="2026-06-01T00:00:00Z",
80
+ ends_at="2026-08-31T23:59:59Z",
81
+ )
82
+
83
+ campaigns = client.list_campaigns()
84
+ fetched = client.get_campaign(campaign.id)
85
+ ```
86
+
87
+ ---
88
+
89
+ ### 3. Generate & Manage Dynamic Deep Links
90
+
91
+ ```python
92
+ link = client.create_dynamic_link(
93
+ client.new_link()
94
+ .deep_path("/products/summer-jacket")
95
+ .custom_alias("summer-sale-2026")
96
+ .campaign_id(campaign.id)
97
+ .utm(source="newsletter", medium="email", campaign="summer_drop")
98
+ .query_param("ref", "vip_creator_42")
99
+ .social_preview(
100
+ title="Summer Jacket - 40% Off",
101
+ description="Shop the exclusive summer collection directly in the app.",
102
+ image_url="https://cdn.yourdomain.com/images/jacket.jpg",
103
+ )
104
+ )
105
+
106
+ print("Dynamic Link URL:", link.url)
107
+ # -> "https://link.yourdomain.com/summer-sale-2026"
108
+
109
+ # List, get, update, or delete existing links
110
+ all_links = client.list_dynamic_links()
111
+ single = client.get_dynamic_link(link.id)
112
+ client.update_dynamic_link(link.id, {"deepPath": "/products/summer-jacket-v2", "status": "ACTIVE"})
113
+ client.delete_dynamic_link(link.id)
114
+ ```
115
+
116
+ ---
117
+
118
+ ### 4. Parse and Resolve a Dynamic Link
119
+
120
+ When your backend receives a dynamic link or short code (e.g. from an affiliate webhook, incoming email click, or QR scan), parse it into its structured payload:
121
+
122
+ ```python
123
+ parsed = client.parse_dynamic_link("summer-sale-2026")
124
+
125
+ print("In-App Route:", parsed.deep_path) # "/products/summer-jacket"
126
+ print("UTM Source:", parsed.query_parameters.get("utm_source")) # "newsletter"
127
+ print("Referral:", parsed.query_parameters.get("ref")) # "vip_creator_42"
128
+ ```
129
+
130
+ ---
131
+
132
+ ### 5. Track Server-Side Conversions
133
+
134
+ Record conversions that occur off-device (e.g. Stripe webhook handler, subscription renewals):
135
+
136
+ ```python
137
+ client.track_event(
138
+ event_type="CONVERSION",
139
+ click_id="550e8400-e29b-41d4-a716-446655440000",
140
+ revenue=129.99,
141
+ idempotency_key="stripe_evt_1Nxyz", # optional: makes retries safe
142
+ currency="USD",
143
+ metadata={
144
+ "order_id": "ORD-12849",
145
+ "plan": "annual_pro",
146
+ },
147
+ )
148
+ ```
149
+
150
+ ---
151
+
152
+ ## Error handling
153
+
154
+ ```python
155
+ from cavlyn import CavlynApiError, CavlynNetworkError
156
+
157
+ try:
158
+ client.get_dynamic_link(link_id)
159
+ except CavlynApiError as e: # non-2xx response
160
+ print(e.status_code, e.message)
161
+ except CavlynNetworkError: # timeout / connection failure
162
+ ...
163
+ ```
164
+
165
+ Requests are not retried automatically. Requires Python 3.9+; no third-party dependencies.
166
+
167
+ ---
168
+
169
+ ## Framework Integration Examples
170
+
171
+ ### FastAPI
172
+
173
+ ```python
174
+ from fastapi import FastAPI
175
+ from cavlyn import CavlynClient
176
+
177
+ app = FastAPI()
178
+ client = CavlynClient(api_key="...", link_domain="https://link.yourdomain.com")
179
+
180
+ @app.post("/api/referral-links")
181
+ def create_referral_link(user_id: str, campaign_id: str | None = None):
182
+ builder = (
183
+ client.new_link()
184
+ .deep_path(f"/invite/{user_id}")
185
+ .custom_alias(f"invite-{user_id}")
186
+ .utm(source="app_referral", medium="in_app", campaign="user_invites")
187
+ )
188
+ if campaign_id:
189
+ builder.campaign_id(campaign_id)
190
+ link = client.create_dynamic_link(builder)
191
+ return {"id": link.id, "dynamic_link": link.url}
192
+ ```
193
+
194
+ ### Django
195
+
196
+ ```python
197
+ # views.py
198
+ from django.conf import settings
199
+ from django.http import JsonResponse
200
+ from cavlyn import CavlynClient
201
+
202
+ client = CavlynClient(api_key=settings.CAVLYN_API_KEY, base_url=settings.CAVLYN_API_URL)
203
+
204
+ def generate_order_link(request, order_id):
205
+ link = client.create_dynamic_link(
206
+ client.new_link()
207
+ .deep_path(f"/orders/{order_id}")
208
+ .utm(source="transactional_email", medium="email", campaign="receipt")
209
+ )
210
+ return JsonResponse({"link_url": link.url})
211
+ ```
212
+
213
+ ---
214
+
215
+ ## API Reference
216
+
217
+ ### `CavlynClient`
218
+
219
+ - `new_link() -> DynamicLink`: Starts a fluent builder.
220
+ - `create_dynamic_link(link: DynamicLink | dict) -> DynamicLinkResponse`: Creates a dynamic link (`POST /api/v1/links`).
221
+ - `list_dynamic_links(app_id: str | None = None) -> list[DynamicLinkResponse]`: Lists links for the app (`GET /api/v1/links`).
222
+ - `get_dynamic_link(link_id: str) -> DynamicLinkResponse`: Gets a single link (`GET /api/v1/links/{id}`).
223
+ - `update_dynamic_link(link_id: str, updates: dict) -> DynamicLinkResponse`: Partially updates a link (`PATCH /api/v1/links/{id}`).
224
+ - `delete_dynamic_link(link_id: str) -> None`: Deletes a link (`DELETE /api/v1/links/{id}`).
225
+ - `create_campaign(name, source=None, medium=None, campaign=None, term=None, content=None, starts_at=None, ends_at=None, app_id=None) -> CampaignResponse`: Creates a campaign (`POST /api/v1/campaigns`).
226
+ - `list_campaigns(app_id: str | None = None) -> list[CampaignResponse]`: Lists campaigns (`GET /api/v1/campaigns`).
227
+ - `get_campaign(campaign_id: str) -> CampaignResponse`: Gets a campaign (`GET /api/v1/campaigns/{id}`).
228
+ - `parse_dynamic_link(code_or_url: str) -> ParsedLink`: Parses/resolves a link (`GET /api/v1/links/resolve`).
229
+ - `track_event(event_type, click_id=None, revenue=None, currency="USD", metadata=None, link_id=None, installation_id=None, idempotency_key=None)`: Sends a server event (`POST /api/v1/events`). Events are only attributed when they carry a `link_id` or `click_id`.
230
+
231
+ ### `DynamicLink` Builder Methods
232
+
233
+ - `.deep_path(path: str)`
234
+ - `.custom_alias(alias: str)`
235
+ - `.app_id(app_id: str)` *(optional when using `X-API-Key`; `.project_id()` kept as deprecated alias)*
236
+ - `.campaign_id(campaign_id: str)`
237
+ - `.utm(source, medium, campaign, term=None, content=None)`
238
+ - `.query_param(key, value)`
239
+ - `.query_params(params: dict)`
240
+ - `.social_preview(title, description, image_url=None)`
241
+ - `.metadata(meta: LinkMetadata | dict)`
242
+ - `.expires_at(expiry: datetime | str)`
243
+ - `.build_payload(default_app_id=None) -> dict`
cavlyn-1.0.0/README.md ADDED
@@ -0,0 +1,218 @@
1
+ # Cavlyn Python Server SDK
2
+
3
+ Official server-side Python library for Cavlyn. Create and manage intelligent dynamic deep links and UTM campaigns, parse/resolve deep links, configure multi-platform routing, and ingest server-side conversion events.
4
+
5
+ ## Features
6
+
7
+ - **Programmatic Dynamic Deep Link CRUD**: Create, list, inspect, update, and delete branded short links from backend services, Celery jobs, transactional emails, or Django/FastAPI applications.
8
+ - **Programmatic Campaign Creation & Querying**: Create and list UTM attribution campaigns and attach `campaign_id` directly to dynamic links.
9
+ - **Automatic App Scoping**: `app_id` is inferred automatically from your `X-API-Key` when omitted.
10
+ - **Deep links for mobile apps**: Links open your app through Universal Links and App Links. What happens when the app isn't installed (App Store, Play Store or web) is configured per app in the Cavlyn dashboard, not per link.
11
+ - **Dynamic Link Parsing & Resolution**: Decode short codes or full dynamic link URLs into structured data, parameters, and campaign tokens.
12
+ - **Open Graph Preview Customizer**: Attach custom social share preview cards for WhatsApp, iMessage, Twitter, and Slack.
13
+ - **Zero Heavy Dependencies**: Built with pure Python standard library (`urllib`, `dataclasses`, `json`), ensuring zero package conflicts in your environment.
14
+
15
+ ---
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ pip install cavlyn
21
+ ```
22
+
23
+ *(Or copy `cavlyn/` directly into your Python project)*
24
+
25
+ ---
26
+
27
+ ## Quickstart
28
+
29
+ ### 1. Initialize Client
30
+
31
+ ```python
32
+ import os
33
+ from cavlyn import CavlynClient
34
+
35
+ client = CavlynClient(
36
+ api_key=os.environ["CAVLYN_API_KEY"],
37
+ base_url="https://api.cavlyn.com", # default; use "http://localhost:8080" for local development
38
+ link_domain="https://link.yourdomain.com", # Branded short link domain used to build link.url
39
+ # timeout=30.0, # seconds
40
+ # default_app_id is optional — inferred automatically from X-API-Key
41
+ )
42
+ ```
43
+
44
+ ---
45
+
46
+ ### 2. Create & List UTM Campaigns
47
+
48
+ ```python
49
+ campaign = client.create_campaign(
50
+ name="Summer Drop 2026",
51
+ source="newsletter",
52
+ medium="email",
53
+ campaign="summer_drop",
54
+ starts_at="2026-06-01T00:00:00Z",
55
+ ends_at="2026-08-31T23:59:59Z",
56
+ )
57
+
58
+ campaigns = client.list_campaigns()
59
+ fetched = client.get_campaign(campaign.id)
60
+ ```
61
+
62
+ ---
63
+
64
+ ### 3. Generate & Manage Dynamic Deep Links
65
+
66
+ ```python
67
+ link = client.create_dynamic_link(
68
+ client.new_link()
69
+ .deep_path("/products/summer-jacket")
70
+ .custom_alias("summer-sale-2026")
71
+ .campaign_id(campaign.id)
72
+ .utm(source="newsletter", medium="email", campaign="summer_drop")
73
+ .query_param("ref", "vip_creator_42")
74
+ .social_preview(
75
+ title="Summer Jacket - 40% Off",
76
+ description="Shop the exclusive summer collection directly in the app.",
77
+ image_url="https://cdn.yourdomain.com/images/jacket.jpg",
78
+ )
79
+ )
80
+
81
+ print("Dynamic Link URL:", link.url)
82
+ # -> "https://link.yourdomain.com/summer-sale-2026"
83
+
84
+ # List, get, update, or delete existing links
85
+ all_links = client.list_dynamic_links()
86
+ single = client.get_dynamic_link(link.id)
87
+ client.update_dynamic_link(link.id, {"deepPath": "/products/summer-jacket-v2", "status": "ACTIVE"})
88
+ client.delete_dynamic_link(link.id)
89
+ ```
90
+
91
+ ---
92
+
93
+ ### 4. Parse and Resolve a Dynamic Link
94
+
95
+ When your backend receives a dynamic link or short code (e.g. from an affiliate webhook, incoming email click, or QR scan), parse it into its structured payload:
96
+
97
+ ```python
98
+ parsed = client.parse_dynamic_link("summer-sale-2026")
99
+
100
+ print("In-App Route:", parsed.deep_path) # "/products/summer-jacket"
101
+ print("UTM Source:", parsed.query_parameters.get("utm_source")) # "newsletter"
102
+ print("Referral:", parsed.query_parameters.get("ref")) # "vip_creator_42"
103
+ ```
104
+
105
+ ---
106
+
107
+ ### 5. Track Server-Side Conversions
108
+
109
+ Record conversions that occur off-device (e.g. Stripe webhook handler, subscription renewals):
110
+
111
+ ```python
112
+ client.track_event(
113
+ event_type="CONVERSION",
114
+ click_id="550e8400-e29b-41d4-a716-446655440000",
115
+ revenue=129.99,
116
+ idempotency_key="stripe_evt_1Nxyz", # optional: makes retries safe
117
+ currency="USD",
118
+ metadata={
119
+ "order_id": "ORD-12849",
120
+ "plan": "annual_pro",
121
+ },
122
+ )
123
+ ```
124
+
125
+ ---
126
+
127
+ ## Error handling
128
+
129
+ ```python
130
+ from cavlyn import CavlynApiError, CavlynNetworkError
131
+
132
+ try:
133
+ client.get_dynamic_link(link_id)
134
+ except CavlynApiError as e: # non-2xx response
135
+ print(e.status_code, e.message)
136
+ except CavlynNetworkError: # timeout / connection failure
137
+ ...
138
+ ```
139
+
140
+ Requests are not retried automatically. Requires Python 3.9+; no third-party dependencies.
141
+
142
+ ---
143
+
144
+ ## Framework Integration Examples
145
+
146
+ ### FastAPI
147
+
148
+ ```python
149
+ from fastapi import FastAPI
150
+ from cavlyn import CavlynClient
151
+
152
+ app = FastAPI()
153
+ client = CavlynClient(api_key="...", link_domain="https://link.yourdomain.com")
154
+
155
+ @app.post("/api/referral-links")
156
+ def create_referral_link(user_id: str, campaign_id: str | None = None):
157
+ builder = (
158
+ client.new_link()
159
+ .deep_path(f"/invite/{user_id}")
160
+ .custom_alias(f"invite-{user_id}")
161
+ .utm(source="app_referral", medium="in_app", campaign="user_invites")
162
+ )
163
+ if campaign_id:
164
+ builder.campaign_id(campaign_id)
165
+ link = client.create_dynamic_link(builder)
166
+ return {"id": link.id, "dynamic_link": link.url}
167
+ ```
168
+
169
+ ### Django
170
+
171
+ ```python
172
+ # views.py
173
+ from django.conf import settings
174
+ from django.http import JsonResponse
175
+ from cavlyn import CavlynClient
176
+
177
+ client = CavlynClient(api_key=settings.CAVLYN_API_KEY, base_url=settings.CAVLYN_API_URL)
178
+
179
+ def generate_order_link(request, order_id):
180
+ link = client.create_dynamic_link(
181
+ client.new_link()
182
+ .deep_path(f"/orders/{order_id}")
183
+ .utm(source="transactional_email", medium="email", campaign="receipt")
184
+ )
185
+ return JsonResponse({"link_url": link.url})
186
+ ```
187
+
188
+ ---
189
+
190
+ ## API Reference
191
+
192
+ ### `CavlynClient`
193
+
194
+ - `new_link() -> DynamicLink`: Starts a fluent builder.
195
+ - `create_dynamic_link(link: DynamicLink | dict) -> DynamicLinkResponse`: Creates a dynamic link (`POST /api/v1/links`).
196
+ - `list_dynamic_links(app_id: str | None = None) -> list[DynamicLinkResponse]`: Lists links for the app (`GET /api/v1/links`).
197
+ - `get_dynamic_link(link_id: str) -> DynamicLinkResponse`: Gets a single link (`GET /api/v1/links/{id}`).
198
+ - `update_dynamic_link(link_id: str, updates: dict) -> DynamicLinkResponse`: Partially updates a link (`PATCH /api/v1/links/{id}`).
199
+ - `delete_dynamic_link(link_id: str) -> None`: Deletes a link (`DELETE /api/v1/links/{id}`).
200
+ - `create_campaign(name, source=None, medium=None, campaign=None, term=None, content=None, starts_at=None, ends_at=None, app_id=None) -> CampaignResponse`: Creates a campaign (`POST /api/v1/campaigns`).
201
+ - `list_campaigns(app_id: str | None = None) -> list[CampaignResponse]`: Lists campaigns (`GET /api/v1/campaigns`).
202
+ - `get_campaign(campaign_id: str) -> CampaignResponse`: Gets a campaign (`GET /api/v1/campaigns/{id}`).
203
+ - `parse_dynamic_link(code_or_url: str) -> ParsedLink`: Parses/resolves a link (`GET /api/v1/links/resolve`).
204
+ - `track_event(event_type, click_id=None, revenue=None, currency="USD", metadata=None, link_id=None, installation_id=None, idempotency_key=None)`: Sends a server event (`POST /api/v1/events`). Events are only attributed when they carry a `link_id` or `click_id`.
205
+
206
+ ### `DynamicLink` Builder Methods
207
+
208
+ - `.deep_path(path: str)`
209
+ - `.custom_alias(alias: str)`
210
+ - `.app_id(app_id: str)` *(optional when using `X-API-Key`; `.project_id()` kept as deprecated alias)*
211
+ - `.campaign_id(campaign_id: str)`
212
+ - `.utm(source, medium, campaign, term=None, content=None)`
213
+ - `.query_param(key, value)`
214
+ - `.query_params(params: dict)`
215
+ - `.social_preview(title, description, image_url=None)`
216
+ - `.metadata(meta: LinkMetadata | dict)`
217
+ - `.expires_at(expiry: datetime | str)`
218
+ - `.build_payload(default_app_id=None) -> dict`
@@ -0,0 +1,27 @@
1
+ from cavlyn._version import __version__
2
+ from cavlyn.builder import DynamicLink
3
+ from cavlyn.client import CavlynClient
4
+ from cavlyn.exceptions import (
5
+ CavlynApiError,
6
+ CavlynError,
7
+ CavlynNetworkError,
8
+ )
9
+ from cavlyn.models import (
10
+ CampaignResponse,
11
+ DynamicLinkResponse,
12
+ LinkMetadata,
13
+ ParsedLink,
14
+ )
15
+
16
+ __all__ = [
17
+ "__version__",
18
+ "CavlynClient",
19
+ "DynamicLink",
20
+ "LinkMetadata",
21
+ "DynamicLinkResponse",
22
+ "ParsedLink",
23
+ "CampaignResponse",
24
+ "CavlynError",
25
+ "CavlynApiError",
26
+ "CavlynNetworkError",
27
+ ]