nodesty.com'un güçlü API'sine Python uygulamalarınızdan kolayca erişmenizi sağlayan modern, asenkron ve tip güvenli bir istemci kütüphanesi. httpx ve pydantic kütüphanelerinin gücünü kullanarak API etkileşimlerinizi basitleştirir.
- ⚡ Asenkron Operasyonlar:
httpxile tam async destek - 🔒 Tip Güvenliği:
pydanticile güçlü veri modelleri ve doğrulama - 🔄 Otomatik Serileştirme: JSON ↔ Python veri tipleri dönüşümü
- ⚙️ Yapılandırılabilir: Timeout, retry, rate limit ayarları
- 🛡️ Kapsamlı Hata Yönetimi: Standart
ApiResponse<T>yapısı - 📦 Modüler Yapı: Her servis kendi modülü içinde
| Servis | Açıklama | Erişim |
|---|---|---|
| User Service | Kullanıcı profili, hizmetler, faturalar, destek biletleri | client.user |
| VPS Service | VPS yönetimi, yedekler, şifre değişimi, istatistikler | client.vps |
| Dedicated Service | Dedicated sunucu yönetimi, donanım bilgileri | client.dedicated_server |
| Firewall Service | nShield kuralları, saldırı logları, rDNS yönetimi | client.firewall |
PyPI üzerinden pip ile kolayca kurabilirsiniz:
pip install nodesty-api-client- Nodesty kontrol paneli adresine giriş yapın.
importasyncioimportosfromnodesty_api_clientimportNodestyApiClient, RestClientOptionsfromdatetimeimporttimedeltaasyncdefmain():
token=os.environ.get("NODESTY_API_TOKEN")
ifnottoken:
raiseValueError("NODESTY_API_TOKEN ortam değişkeni ayarlanmamış.")
options=RestClientOptions(access_token=token)
.with_timeout(timedelta(seconds=45))
.with_retry(5)
.with_rate_limit_offset(timedelta(milliseconds=100))
# Asenkron bağlam yöneticisi olarak NodestyApiClient'i kullanınasyncwithNodestyApiClient(options) asclient:
user_response=awaitclient.user.get_current_user()
ifuser_response.success:
ifuser_response.data:
print(f"Hoş geldin {user_response.data.name}")
else:
print("Kullanıcı bilgisi bulunamadı.")
else:
print(f"Kullanıcı bilgisi getirilirken hata oluştu: {user_response.error}")
if__name__=="__main__":
asyncio.run(main())importasyncioimportosfromnodesty_api_clientimportNodestyApiClient, RestClientOptionsasyncdefget_user_info():
token=os.environ.get("NODESTY_API_TOKEN")
options=RestClientOptions(access_token=token)
asyncwithNodestyApiClient(options) asclient:
res=awaitclient.user.get_current_user()
ifres.successandres.data:
user=res.dataprint(f"Merhaba {user.full_name}")
print(f"Email: {user.email}")
else:
print(f"Hata: {res.error}")
if__name__=="__main__":
asyncio.run(get_user_info())importasyncioimportosfromnodesty_api_clientimportNodestyApiClient, RestClientOptionsfromnodesty_api_client.models.vpsimportVpsActionasyncdefmanage_vps():
token=os.environ.get("NODESTY_API_TOKEN")
options=RestClientOptions(access_token=token)
asyncwithNodestyApiClient(options) asclient:
vps_id="your-vps-id"# VPS'i yeniden başlatrestart_res=awaitclient.vps.perform_action(vps_id, VpsAction.RESTART)
ifrestart_res.success:
print(f"VPS {vps_id} başarıyla yeniden başlatıldı.")
else:
print(f"VPS yeniden başlatılırken hata oluştu: {restart_res.error}")
# Yedekleri listelebackups_res=awaitclient.vps.get_backups(vps_id)
ifbackups_res.successandbackups_res.data:
print("Yedekler:")
forbackupinbackups_res.data:
print(f"- Tarih: {backup.date}, Dosya: {backup.file}")
else:
print(f"Yedekler getirilirken hata oluştu: {backups_res.error}")
if__name__=="__main__":
asyncio.run(manage_vps())importasyncioimportosfromnodesty_api_clientimportNodestyApiClient, RestClientOptionsasyncdefget_dedicated_info():
token=os.environ.get("NODESTY_API_TOKEN")
options=RestClientOptions(access_token=token)
asyncwithNodestyApiClient(options) asclient:
dedicated_id="your-dedicated-id"res=awaitclient.dedicated_server.get_hardware_components(dedicated_id)
ifres.successandres.data:
print("Donanım Bileşenleri:")
forpartinres.data:
print(f"- {part.component}: {part.model}{part.value}{part.value_suffix}")
else:
print(f"Donanım bileşenleri getirilirken hata oluştu: {res.error}")
if__name__=="__main__":
asyncio.run(get_dedicated_info())importasyncioimportosfromnodesty_api_clientimportNodestyApiClient, RestClientOptionsfromnodesty_api_client.models.firewallimportFirewallCreateRuleDataasyncdefmanage_firewall():
token=os.environ.get("NODESTY_API_TOKEN")
options=RestClientOptions(access_token=token)
asyncwithNodestyApiClient(options) asclient:
service_id="your-service-id"ip_address="your-ip-address"# Yeni bir kural oluşturrule_data=FirewallCreateRuleData(port=25565, app_id=123)
create_res=awaitclient.firewall.create_rule(service_id, ip_address, rule_data)
ifcreate_res.success:
print("Güvenlik duvarı kuralı başarıyla oluşturuldu.")
else:
print(f"Kural oluşturulurken hata oluştu: {create_res.error}")
# Saldırı kayıtlarını getirlogs_res=awaitclient.firewall.get_attack_logs(service_id, ip_address)
iflogs_res.successandlogs_res.data:
print("Saldırı Kayıtları:")
forloginlogs_res.data:
print(f"- Başlangıç: {log.started_at}, Vektörler: {log.vectors}")
else:
print(f"Saldırı kayıtları getirilirken hata oluştu: {logs_res.error}")
if__name__=="__main__":
asyncio.run(manage_firewall())Tüm API çağrıları ApiResponse<T> döner:
fromtypingimportTypeVar, Generic, OptionalfrompydanticimportBaseModelT=TypeVar('T')
classApiResponse(BaseModel, Generic[T]):
success: boolerror: Optional[str] =Nonedata: Optional[T] =Nonefromnodesty_api_clientimportRestClientOptionsfromdatetimeimporttimedeltaoptions=RestClientOptions(access_token="YOUR_API_TOKEN")
.with_timeout(timedelta(seconds=30))
.with_retry(3)
.with_rate_limit_offset(timedelta(milliseconds=50))| Metod | Açıklama | Endpoint |
|---|---|---|
get_current_user() | Kullanıcı profilini al | GET /users/@me |
get_services() | Hizmetleri listele | GET /services |
get_tickets() | Destek biletlerini listele | GET /tickets |
get_ticket_by_id(id) | Belirli bileti getir | GET /tickets/{id} |
get_invoices() | Faturaları listele | GET /users/@me/invoices |
get_invoice_by_id(id) | Belirli faturayı getir | GET /users/@me/invoices/{id} |
get_sessions() | Aktif oturumları getir | GET /users/@me/sessions |
| Metod | Açıklama | Endpoint |
|---|---|---|
perform_action(id, action) | VPS eylemi gerçekleştir | POST /services/{id}/vps/action |
get_backups(id) | Yedekleri getir | GET /services/{id}/vps/backups |
restore_backup(id, data) | Geri yükleme yap | POST /services/{id}/vps/backup/restore |
change_password(id, data) | Şifre değiştir | POST /services/{id}/vps/change-password |
get_graphs(id) | İstatistikleri al | GET /services/{id}/vps/graphs |
get_details(id) | VPS detayları | GET /services/{id}/vps/info |
get_os_templates(id) | OS şablonlarını getir | GET /services/{id}/vps/os-templates |
reinstall(id, data) | Yeniden kurulum | POST /services/{id}/vps/reinstall |
get_tasks(id) | Görevleri getir | GET /services/{id}/vps/tasks |
| Metod | Açıklama | Endpoint |
|---|---|---|
perform_action(id, action) | Eylem çalıştır | POST /services/{id}/dedicated/action |
get_hardware_components(id) | Donanım detayları | GET /services/{id}/dedicated/hardware |
get_details(id) | Sunucu bilgisi | GET /services/{id}/dedicated/info |
get_os_templates(id) | OS şablonları | GET /services/{id}/dedicated/os-templates |
get_reinstall_status(id) | Kurulum durumu | GET /services/{id}/dedicated/reinstall-status |
reinstall(id, data) | Yeniden kur | POST /services/{id}/dedicated/reinstall |
get_tasks(id) | Görevleri getir | GET /services/{id}/dedicated/tasks |
| Metod | Açıklama | Endpoint |
|---|---|---|
get_attack_logs(id, ip) | Saldırı kayıtlarını getir | GET /services/{id}/firewall/{ip}/attack-logs |
get_attack_notification_settings(id, ip) | Bildirim ayarları | GET /services/{id}/firewall/{ip}/attack-notification |
update_attack_notification_settings(id, ip, data) | Bildirim ayarlarını güncelle | PUT /services/{id}/firewall/{ip}/attack-notification |
delete_reverse_dns(id, ip) | rDNS kaldır | DELETE /services/{id}/firewall/{ip}/rdns |
get_reverse_dns(id, ip) | rDNS bilgisi | GET /services/{id}/firewall/{ip}/rdns |
upsert_reverse_dns(id, ip, rdns_data) | rDNS ayarla | PUT /services/{id}/firewall/{ip}/rdns |
delete_rule(id, ip, rule_id) | Kural sil | DELETE /services/{id}/firewall/{ip}/rules/{rule_id} |
get_rules(id, ip) | Kuralları getir | GET /services/{id}/firewall/{ip}/rules |
create_rule(id, ip, data) | Kural oluştur | POST /services/{id}/firewall/{ip}/rules |
get_statistics(id, ip) | İstatistikleri getir | GET /services/{id}/firewall/{ip}/stats |
- API token'ınızı doğrudan kodda tutmayın. Ortam değişkenlerinden (env vars) veya güvenli bir yapılandırma dosyasından alın
- Her
ApiResponsesonrası.successözelliğini kontrol edin - Hataları uygun try-except blokları veya if-else yapılarıyla detaylı olarak yönetin
- Asenkron işlemleri
asyncio.gather()ile paralel çalıştırın - Gecikmeleri azaltmak için
RestClientOptionsiçinde timeout ve rate limit ayarlarını yapılandırın - Uygulama başında
NodestyApiClient'i bir kere oluşturun ve tüm uygulamanız boyunca tekrar kullanın (async withifadesi ile otomatik kapanmasını sağlayabilirsiniz)
importasyncioimportosfromnodesty_api_clientimportNodestyApiClient, RestClientOptionsasyncdeftest_user_service():
token=os.environ.get("NODESTY_TEST_TOKEN")
ifnottoken:
raiseValueError("NODESTY_TEST_TOKEN ortam değişkeni ayarlanmamış.")
options=RestClientOptions(access_token=token)
asyncwithNodestyApiClient(options) asclient:
response=awaitclient.user.get_current_user()
assertresponse.success, f"Test başarısız: {response.error}"assertresponse.dataand"@"inresponse.data.email, "Kullanıcı bilgisi veya email bulunamadı."print("Kullanıcı servisi testi başarılı!")
if__name__=="__main__":
asyncio.run(test_user_service())httpx.HTTPStatusError: 401 Unauthorized
- API token'ınız geçersiz veya süresi dolmuş olabilir. Nodesty kontrol panelinden kontrol edin
httpx.ConnectTimeout veya benzeri Timeout hataları
- Ağ bağlantınızı ve
RestClientOptionsiçindeki timeout süresini kontrol edin. Gerekirse artırın
Too Many Requests (429 Hata)
- API'nin rate limitine takılmış olabilirsiniz.
RestClientOptionsiçindekirate_limit_offsetdeğerini artırın veya istekler arasında daha fazla bekleme süresi ekleyin
- Bu depoyu (repository) fork'layın
- Yeni bir özellik veya hata düzeltmesi için bir branch oluşturun (
git checkout -b feature/harika-ozellik) - Değişikliklerinizi yapın ve commit'leyin
- Remote deponuza push yapın
- Bir Pull Request (PR) gönderin
Bu proje faydalı olduysa bir yıldız (⭐) vererek destekleyebilirsiniz!
Made with ❤️ for Nodesty Community.