FortiCare Asset Management API Client
Project description
hfortix-forticare
Python SDK for Fortinet FortiCare Asset Management V3 API.
Overview
hfortix-forticare provides a fully typed Python interface to the FortiCare Asset Management API, enabling programmatic access to:
- Product Management: Register, list, update, and decommission products
- License Management: Register, list, and download licenses
- Contract Management: View contract information
- Folder Management: Organize assets into folders
- Service Management: Register subscription services
Features
โจ Fully Typed - Complete type hints with TypedDict for request/response structures ๐ Auto-completion - IDE auto-completion for all parameters and return values ๐ OAuth 2.0 - Built-in OAuth Bearer token authentication ๐ Modern HTTP - HTTP/2 support via httpx ๐ฏ Explicit Parameters - All API parameters exposed as function arguments ๐ Rich Documentation - Comprehensive docstrings from Swagger specs
Installation
pip install hfortix-forticare
Quick Start
1. Obtain OAuth Token
First, create an API user through the IAM portal and obtain an OAuth token:
# Get token from FortiAuthenticator OAuth endpoint
# https://customerapiauth.fortinet.com/api/v1/oauth/token
2. Initialize Client
from hfortix_forticare import FortiCare
fcc = FortiCare(oauth_token="your_oauth_token_here")
3. Use the API
# List products with entitlements
products = fcc.api.products.list.post(
serial_number="FGT*",
status="Registered"
)
# Get product details
details = fcc.api.products.details.post(
serial_number="FGT90D1234567890"
)
# Register a product
result = fcc.api.products.register.post(
registration_units=[
{
"serialNumber": "FGT90D1234567890",
"description": "My FortiGate",
# ... other fields
}
]
)
# List contracts
contracts = fcc.api.contracts.list.post()
# List licenses
licenses = fcc.api.licenses.list.post()
# Manage folders
folders = fcc.api.folders.list.post()
# Always clean up when done
fcc.logout()
API Structure
The SDK mirrors the FortiCare Asset Management V3 API structure:
fcc.api.
โโโ products.
โ โโโ list - List products with entitlements
โ โโโ register - Register products and contracts
โ โโโ details - Get product details
โ โโโ description - Update product description
โ โโโ location - Update product location
โ โโโ folder - Update product folder
โ โโโ decommission - Decommission products
โ โโโ transfer - Transfer products between accounts
โโโ licenses.
โ โโโ list - List licenses
โ โโโ register - Register a license
โ โโโ download - Download VM license file
โโโ contracts.
โ โโโ list - List contracts
โโโ folders.
โ โโโ list - List asset folders
โ โโโ create - Create new folder
โ โโโ delete - Delete folder
โโโ services.
โโโ register - Register subscription service
Type Safety
All endpoints use TypedDict for request and response structures:
# IDE will show all available parameters
products = fcc.api.products.list.post(
serial_number="FGT*", # str
expire_before="2024...", # str (ISO 8601)
status="Registered", # str
product_model="...", # str
account_id=12345 # float
)
# Response is also typed
assert products['status'] == 0 # int
assert isinstance(products['message'], str)
assert isinstance(products['assets'], list)
Rate Limits
FortiCare Asset Management API enforces the following limits:
- 100 calls per minute
- 1000 calls per hour
- 10 errors per hour
- Batch operations: Max 10 units, max 5 errors per batch
Error Handling
try:
result = fcc.api.products.list.post(serial_number="FGT*")
if result['status'] == 0:
print("Success!")
else:
print(f"API Error: {result['message']}")
except httpx.HTTPStatusError as e:
print(f"HTTP Error: {e.response.status_code}")
except httpx.TimeoutException:
print("Request timed out")
except httpx.RequestError as e:
print(f"Network error: {e}")
Context Manager
Use as a context manager for automatic cleanup:
with FortiCare(oauth_token="...") as fcc:
products = fcc.api.products.list.post(...)
# ... use the client ...
# Automatically logged out
Configuration
fcc = FortiCare(
oauth_token="your_token",
base_url="https://support.fortinet.com", # Default
verify=True, # SSL verification
max_retries=3, # Retry attempts
connect_timeout=10.0, # Connection timeout (seconds)
read_timeout=300.0 # Read timeout (seconds)
)
Examples
See EXAMPLES.py for more comprehensive examples.
Development
Regenerating the SDK
If Fortinet updates the API, regenerate the SDK:
cd packages/forticare/dev/generator
python generate.py --clean
This will:
- Parse updated Swagger JSON files
- Generate all endpoint classes with type hints
- Create .pyi stub files for IDE support
- Generate category and main init.py files
Project Structure
packages/forticare/
โโโ src/
โ โโโ hfortix_forticare/
โ โโโ __init__.py # Main FortiCare client
โ โโโ api/
โ โโโ v3/
โ โโโ __init__.py # V3API class
โ โโโ products/ # Product endpoints
โ โโโ licenses/ # License endpoints
โ โโโ contracts/ # Contract endpoints
โ โโโ folders/ # Folder endpoints
โ โโโ services/ # Service endpoints
โโโ dev/
โ โโโ generator/
โ โโโ generate.py # Code generator
โ โโโ parsers/ # Swagger parsers
โ โโโ generators/ # Code generators
โ โโโ templates/ # Code templates
โ โโโ swagger/ # Swagger JSON files
โโโ README.md
Requirements
- Python 3.10+
- httpx
- hfortix-core
License
Copyright ยฉ 2024 Fortinet, Inc.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hfortix_forticare-0.5.160.tar.gz.
File metadata
- Download URL: hfortix_forticare-0.5.160.tar.gz
- Upload date:
- Size: 25.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36099687480db1ef83f0841681654728fa3a98358cdeda05b94d22ccb27b64a8
|
|
| MD5 |
8341285564917fd5f1ff3e54bd8d093e
|
|
| BLAKE2b-256 |
7f5b0d60f8aeb85c8ee7bdfacc05c621e2a11ba3188372c284690feff7df7949
|
File details
Details for the file hfortix_forticare-0.5.160-py3-none-any.whl.
File metadata
- Download URL: hfortix_forticare-0.5.160-py3-none-any.whl
- Upload date:
- Size: 60.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58b4a0686fb6ab571e06f4579cbfe039f1af63d79d4d78b331129fc115f8a5fa
|
|
| MD5 |
9c0425137b61a84e202952400ac64ca6
|
|
| BLAKE2b-256 |
23b641768f622019c7fdc149dfc7008ef832c551b6fa6214bb431867e5a97c8e
|