finaegis 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.
@@ -0,0 +1,435 @@
1
+ Metadata-Version: 2.4
2
+ Name: finaegis
3
+ Version: 1.0.0
4
+ Summary: Official Python SDK for the FinAegis API
5
+ Home-page: https://github.com/FinAegis/finaegis-python
6
+ Author: FinAegis
7
+ Author-email: sdk@finaegis.org
8
+ Project-URL: Bug Reports, https://github.com/FinAegis/finaegis-python/issues
9
+ Project-URL: Source, https://github.com/FinAegis/finaegis-python
10
+ Project-URL: Documentation, https://docs.finaegis.org/sdks/python
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.7
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Requires-Python: >=3.7
22
+ Description-Content-Type: text/markdown
23
+ Requires-Dist: requests>=2.28.0
24
+ Requires-Dist: urllib3>=1.26.0
25
+ Requires-Dist: python-dateutil>=2.8.0
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest>=7.0; extra == "dev"
28
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
29
+ Requires-Dist: pytest-asyncio>=0.20; extra == "dev"
30
+ Requires-Dist: black>=22.0; extra == "dev"
31
+ Requires-Dist: flake8>=5.0; extra == "dev"
32
+ Requires-Dist: mypy>=0.990; extra == "dev"
33
+ Requires-Dist: requests-mock>=1.9.0; extra == "dev"
34
+ Provides-Extra: async
35
+ Requires-Dist: aiohttp>=3.8.0; extra == "async"
36
+ Dynamic: author
37
+ Dynamic: author-email
38
+ Dynamic: classifier
39
+ Dynamic: description
40
+ Dynamic: description-content-type
41
+ Dynamic: home-page
42
+ Dynamic: project-url
43
+ Dynamic: provides-extra
44
+ Dynamic: requires-dist
45
+ Dynamic: requires-python
46
+ Dynamic: summary
47
+
48
+ # FinAegis Python SDK
49
+
50
+ Official Python SDK for the FinAegis API.
51
+
52
+ ## Installation
53
+
54
+ ```bash
55
+ pip install finaegis
56
+ ```
57
+
58
+ ## Quick Start
59
+
60
+ ```python
61
+ from finaegis import FinAegis
62
+
63
+ # Initialize the client
64
+ client = FinAegis(
65
+ api_key='your-api-key',
66
+ environment='sandbox' # or 'production'
67
+ )
68
+
69
+ # List accounts
70
+ accounts = client.accounts.list()
71
+ for account in accounts.data:
72
+ print(f"{account.name}: ${account.balance / 100:.2f}")
73
+
74
+ # Create a new account
75
+ account = client.accounts.create(
76
+ user_uuid='user-uuid',
77
+ name='My Savings Account',
78
+ initial_balance=10000 # in cents
79
+ )
80
+
81
+ # Make a transfer
82
+ transfer = client.transfers.create(
83
+ from_account='account-uuid-1',
84
+ to_account='account-uuid-2',
85
+ amount=5000, # in cents
86
+ asset_code='USD',
87
+ reference='Payment for services'
88
+ )
89
+ ```
90
+
91
+ ## Configuration
92
+
93
+ ### Basic Configuration
94
+
95
+ ```python
96
+ client = FinAegis(
97
+ api_key='your-api-key',
98
+ environment='production', # 'production' | 'sandbox' | 'local'
99
+ timeout=30, # Request timeout in seconds
100
+ max_retries=3 # Number of retries for failed requests
101
+ )
102
+ ```
103
+
104
+ ### Environment Variables
105
+
106
+ You can also set your API key via environment variable:
107
+
108
+ ```bash
109
+ export FINAEGIS_API_KEY='your-api-key'
110
+ ```
111
+
112
+ Then initialize without passing the key:
113
+
114
+ ```python
115
+ client = FinAegis(environment='sandbox')
116
+ ```
117
+
118
+ ## Resources
119
+
120
+ ### Accounts
121
+
122
+ ```python
123
+ # List all accounts
124
+ accounts = client.accounts.list(page=1, per_page=20)
125
+
126
+ # Get account details
127
+ account = client.accounts.get('account-uuid')
128
+
129
+ # Get account balances
130
+ balances = client.accounts.get_balances('account-uuid')
131
+
132
+ # Deposit funds
133
+ deposit = client.accounts.deposit('account-uuid', 10000, 'USD')
134
+
135
+ # Withdraw funds
136
+ withdrawal = client.accounts.withdraw('account-uuid', 5000, 'USD')
137
+
138
+ # Freeze/unfreeze account
139
+ client.accounts.freeze('account-uuid', 'Suspicious activity')
140
+ client.accounts.unfreeze('account-uuid', 'Investigation completed')
141
+
142
+ # Get transaction history
143
+ transactions = client.accounts.get_transactions('account-uuid')
144
+ ```
145
+
146
+ ### Transfers
147
+
148
+ ```python
149
+ # Create a transfer
150
+ transfer = client.transfers.create(
151
+ from_account='account-uuid-1',
152
+ to_account='account-uuid-2',
153
+ amount=10000,
154
+ asset_code='USD',
155
+ reference='Invoice #123'
156
+ )
157
+
158
+ # Get transfer details
159
+ transfer_details = client.transfers.get('transfer-uuid')
160
+ ```
161
+
162
+ ### Exchange Rates
163
+
164
+ ```python
165
+ # Get exchange rate
166
+ rate = client.exchange_rates.get('USD', 'EUR')
167
+ print(f"1 USD = {rate.rate} EUR")
168
+
169
+ # Convert currency
170
+ conversion = client.exchange_rates.convert('USD', 'EUR', 100)
171
+ print(f"${conversion['from_amount']} = €{conversion['to_amount']}")
172
+
173
+ # Refresh rates
174
+ client.exchange_rates.refresh()
175
+ ```
176
+
177
+ ### GCU (Global Currency Unit)
178
+
179
+ ```python
180
+ # Get GCU composition
181
+ composition = client.gcu.get_composition()
182
+ for asset in composition.composition:
183
+ print(f"{asset.asset_code}: {asset.percentage_of_basket}%")
184
+
185
+ # Get value history
186
+ history = client.gcu.get_value_history(period='7d', interval='daily')
187
+
188
+ # Get active governance polls
189
+ polls = client.gcu.get_active_polls()
190
+ ```
191
+
192
+ ### Webhooks
193
+
194
+ ```python
195
+ # Create a webhook
196
+ webhook = client.webhooks.create(
197
+ name='Transaction Updates',
198
+ url='https://your-app.com/webhooks',
199
+ events=['transaction.created', 'transaction.completed'],
200
+ secret='your-webhook-secret'
201
+ )
202
+
203
+ # List webhook deliveries
204
+ deliveries = client.webhooks.get_deliveries(webhook.uuid)
205
+
206
+ # Get available events
207
+ events = client.webhooks.get_events()
208
+ ```
209
+
210
+ ### Baskets
211
+
212
+ ```python
213
+ # Get basket information
214
+ basket = client.baskets.get('GCU')
215
+
216
+ # Get basket value history
217
+ history = client.baskets.get_history('GCU', period='30d')
218
+
219
+ # Create a custom basket
220
+ basket = client.baskets.create(
221
+ code='MYBASKET',
222
+ name='My Custom Basket',
223
+ composition={'USD': 0.5, 'EUR': 0.3, 'GBP': 0.2}
224
+ )
225
+
226
+ # Compose/decompose basket tokens
227
+ client.baskets.compose('account-uuid', 'GCU', 1000)
228
+ client.baskets.decompose('account-uuid', 'GCU', 500)
229
+ ```
230
+
231
+ ## Error Handling
232
+
233
+ ```python
234
+ from finaegis import FinAegisError, ValidationError, NotFoundError, RateLimitError
235
+
236
+ try:
237
+ account = client.accounts.get('invalid-uuid')
238
+ except NotFoundError as e:
239
+ print(f"Account not found: {e}")
240
+ except ValidationError as e:
241
+ print(f"Validation error: {e}")
242
+ print(f"Errors: {e.errors}")
243
+ except RateLimitError as e:
244
+ print(f"Rate limit exceeded. Retry after {e.retry_after} seconds")
245
+ except FinAegisError as e:
246
+ print(f"API error: {e}")
247
+ print(f"Status code: {e.status_code}")
248
+ ```
249
+
250
+ ## Type Hints
251
+
252
+ The SDK provides comprehensive type hints for all methods and responses:
253
+
254
+ ```python
255
+ from finaegis import FinAegis, Account, Transfer
256
+ from typing import List
257
+
258
+ def get_high_value_accounts(client: FinAegis, min_balance: float) -> List[Account]:
259
+ """Get all accounts with balance above threshold."""
260
+ accounts = client.accounts.list()
261
+ return [
262
+ account for account in accounts.data
263
+ if account.balance >= min_balance * 100 # Convert to cents
264
+ ]
265
+ ```
266
+
267
+ ## Async Support
268
+
269
+ For async operations, install with async support:
270
+
271
+ ```bash
272
+ pip install finaegis[async]
273
+ ```
274
+
275
+ Then use the async client:
276
+
277
+ ```python
278
+ import asyncio
279
+ from finaegis.async_client import AsyncFinAegis
280
+
281
+ async def main():
282
+ client = AsyncFinAegis(api_key='your-api-key')
283
+
284
+ # Concurrent requests
285
+ accounts, rates = await asyncio.gather(
286
+ client.accounts.list(),
287
+ client.exchange_rates.list()
288
+ )
289
+
290
+ print(f"Found {len(accounts.data)} accounts")
291
+ print(f"Found {len(rates.data)} exchange rates")
292
+
293
+ asyncio.run(main())
294
+ ```
295
+
296
+ ## Webhook Signature Verification
297
+
298
+ ```python
299
+ import hmac
300
+ import hashlib
301
+
302
+ def verify_webhook_signature(payload: str, signature: str, secret: str) -> bool:
303
+ """Verify webhook signature."""
304
+ expected_signature = hmac.new(
305
+ secret.encode(),
306
+ payload.encode(),
307
+ hashlib.sha256
308
+ ).hexdigest()
309
+
310
+ return hmac.compare_digest(signature, expected_signature)
311
+
312
+ # In your webhook handler
313
+ @app.route('/webhooks', methods=['POST'])
314
+ def handle_webhook():
315
+ payload = request.get_data(as_text=True)
316
+ signature = request.headers.get('X-FinAegis-Signature')
317
+
318
+ if not verify_webhook_signature(payload, signature, 'your-secret'):
319
+ return 'Invalid signature', 401
320
+
321
+ # Process webhook
322
+ data = json.loads(payload)
323
+ print(f"Received {data['event']} event")
324
+
325
+ return 'OK', 200
326
+ ```
327
+
328
+ ## Advanced Usage
329
+
330
+ ### Custom Requests
331
+
332
+ ```python
333
+ # Make custom API requests
334
+ response = client.request(
335
+ method='GET',
336
+ path='/custom-endpoint',
337
+ params={'key': 'value'}
338
+ )
339
+ ```
340
+
341
+ ### Pagination
342
+
343
+ ```python
344
+ # Iterate through all pages
345
+ page = 1
346
+ all_accounts = []
347
+
348
+ while True:
349
+ response = client.accounts.list(page=page, per_page=50)
350
+ all_accounts.extend(response.data)
351
+
352
+ if page >= response.last_page:
353
+ break
354
+
355
+ page += 1
356
+
357
+ print(f"Total accounts: {len(all_accounts)}")
358
+ ```
359
+
360
+ ### Retry Configuration
361
+
362
+ ```python
363
+ # Custom retry configuration
364
+ client = FinAegis(
365
+ api_key='your-api-key',
366
+ max_retries=5, # Increase retries
367
+ timeout=60 # Increase timeout
368
+ )
369
+ ```
370
+
371
+ ## Examples
372
+
373
+ ### Complete Payment Flow
374
+
375
+ ```python
376
+ def process_payment(client: FinAegis, from_account_id: str, to_account_id: str, amount_usd: float):
377
+ """Process a payment between two accounts."""
378
+ try:
379
+ # Convert dollars to cents
380
+ amount_cents = int(amount_usd * 100)
381
+
382
+ # Check sender balance
383
+ balances = client.accounts.get_balances(from_account_id)
384
+ usd_balance = next(
385
+ (b for b in balances['balances'] if b['asset_code'] == 'USD'),
386
+ None
387
+ )
388
+
389
+ if not usd_balance or float(usd_balance['available_balance']) < amount_cents:
390
+ raise ValueError("Insufficient balance")
391
+
392
+ # Create transfer
393
+ transfer = client.transfers.create(
394
+ from_account=from_account_id,
395
+ to_account=to_account_id,
396
+ amount=amount_cents,
397
+ asset_code='USD',
398
+ reference=f"Payment on {datetime.now().isoformat()}"
399
+ )
400
+
401
+ print(f"Transfer completed: {transfer.uuid}")
402
+ return transfer
403
+
404
+ except Exception as e:
405
+ print(f"Payment failed: {e}")
406
+ raise
407
+ ```
408
+
409
+ ### Monitoring Account Activity
410
+
411
+ ```python
412
+ def monitor_account_activity(client: FinAegis, account_id: str):
413
+ """Monitor recent account activity."""
414
+ # Get recent transactions
415
+ transactions = client.accounts.get_transactions(account_id, per_page=10)
416
+
417
+ print(f"Recent transactions for account {account_id}:")
418
+ for tx in transactions.data:
419
+ sign = '+' if tx.type == 'deposit' else '-'
420
+ print(f"{tx.created_at}: {sign}${tx.amount / 100:.2f} - {tx.status}")
421
+
422
+ # Get recent transfers
423
+ transfers = client.accounts.get_transfers(account_id, per_page=10)
424
+
425
+ print(f"\nRecent transfers:")
426
+ for transfer in transfers.data:
427
+ if transfer.from_account == account_id:
428
+ print(f"{transfer.created_at}: Sent ${transfer.amount / 100:.2f} to {transfer.to_account}")
429
+ else:
430
+ print(f"{transfer.created_at}: Received ${transfer.amount / 100:.2f} from {transfer.from_account}")
431
+ ```
432
+
433
+ ## License
434
+
435
+ MIT