Lightweight Python Read-Only Property Decorator
Project description
🚀 py-readonlyx
Lightweight Python Read-Only Property Decorator
Periyodik görevlerinizi kolayca yönetin - Sıfır bağımlılık, maksimum performans
📖 Genel Bakış
py-readonlyx, Python sınıflarında read-only (salt okunur) property'ler oluşturmak için tasarlanmış minimal ve yüksek performanslı bir decorator kütüphanesidir. Sadece tek bir decorator ile property'lerinizi değiştirilemez hale getirebilirsiniz.
🎯 Neden py-readonlyx?
🆚 Diğer Çözümlerle Karşılaştırma
| Özellik | py-readonlyx | Manuel Property | dataclasses.frozen | attrs.frozen |
|---|---|---|---|---|
| Basitlik | ✅ Tek decorator | ❌ Çok kod | ⚠️ Sınıf seviyesi | ⚠️ Bağımlılık |
| Performans | ✅ Yüksek | ✅ Yüksek | ⚠️ Orta | ⚠️ Orta |
| Bağımlılık | ✅ Sıfır | ✅ Sıfır | ✅ Stdlib | ❌ Dış paket |
| Seçici Control | ✅ Property bazlı | ✅ Property bazlı | ❌ Tüm sınıf | ❌ Tüm sınıf |
| Mutable Fields | ✅ Destekler | ✅ Destekler | ❌ Desteklemez | ❌ Desteklemez |
💡 Neden Bu Kütüphaneyi Seçmelisiniz?
- 🏃♂️ Sıfır Öğrenme Eğrisi: Sadece
@readonlyekleyin, hazır! - ⚡ Yüksek Performans: Native Python property'lerinin performansı
- 🪶 Sıfır Bağımlılık: Harici paket gerektirmez
- 🎛️ Granüler Kontrol: Sadece istediğiniz property'leri readonly yapın
- 🔄 Karma Kullanım: Aynı sınıfta readonly ve normal property'ler
- 🧵 Thread-Safe: Çoklu thread ortamlarında güvenli
- 📦 Minimal Footprint: Toplam ~50 satır kod
🚀 Hızlı Başlangıç
Kurulum
# Bu projeyi klonlayın
git clone https://github.com/yourusername/py-readonlyx.git
cd py-readonlyx
# Python path'inize ekleyin veya doğrudan import edin
Temel Kullanım
from py_readonlyx import readonly, ReadOnlyError
class User:
def __init__(self, name="Fırat", age=25):
self._name = name
self._age = age
self._status = "active" # Bu değiştirilebilir
@readonly
def name(self):
"""Kullanıcı adı - salt okunur"""
return self._name
@readonly
def age(self):
"""Kullanıcı yaşı - salt okunur"""
return self._age
# Normal property - değiştirilebilir
@property
def status(self):
return self._status
@status.setter
def status(self, value):
self._status = value
# Kullanım
user = User("Ahmet", 30)
# ✅ Okuma işlemleri
print(user.name) # "Ahmet"
print(user.age) # 30
# ✅ Normal property değişikliği
user.status = "inactive" # Çalışır
# ❌ Read-only property değişikliği
user.name = "Mehmet" # ReadOnlyError
user.age = 35 # ReadOnlyError
del user.name # ReadOnlyError
🛠️ Gelişmiş Kullanım
API Referansı
@readonly Decorator
Property'yi salt okunur hale getirir.
@readonly
def property_name(self):
return self._value
ReadOnlyError Exception
Read-only property'ye yazma/silme girişiminde fırlatılır.
try:
user.readonly_prop = "new_value"
except ReadOnlyError as e:
print(f"Hata: {e}")
# "Cannot set read-only property 'readonly_prop'"
Kullanım Senaryoları
1. Immutable Model Classes
class Point:
def __init__(self, x, y):
self._x, self._y = x, y
@readonly
def x(self): return self._x
@readonly
def y(self): return self._y
2. Configuration Objects
class Config:
def __init__(self, api_key, database_url):
self._api_key = api_key
self._database_url = database_url
@readonly
def api_key(self): return self._api_key
@readonly
def database_url(self): return self._database_url
3. Computed Properties
class Circle:
def __init__(self, radius):
self._radius = radius
@property
def radius(self): return self._radius
@radius.setter
def radius(self, value): self._radius = value
@readonly
def area(self): return 3.14159 * self._radius ** 2
@readonly
def circumference(self): return 2 * 3.14159 * self._radius
🧪 Test Etme
# Test suite'i çalıştır
python main.py
# Beklenen çıktı:
# ✅ Tüm read-only testleri geçti
# ✅ Multiple instance desteği çalışıyor
# ✅ Exception handling doğru
📊 Performans
import timeit
# py-readonlyx (@readonly)
def test_readonly():
return user.readonly_prop
# Manuel property
def test_manual():
return user.manual_prop
# Her ikisi de ~aynı performans (native property hızı)
🤝 Katkıda Bulunma
- Fork edin
- Feature branch oluşturun (
git checkout -b feature/amazing-feature) - Commit edin (
git commit -m 'Add amazing feature') - Push edin (
git push origin feature/amazing-feature) - Pull Request açın
📄 Lisans
Apache 2.0 License - Detaylar için LICENSE dosyasına bakın.
🏷️ Versiyon Geçmişi
- v1.0.0 - İlk kararlı sürüm
@readonlydecoratorReadOnlyErrorexception- Tam test coverage
⭐ Beğendiyseniz yıldız vermeyi unutmayın!
Created by ❤️ firatmio
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 py_readonlyx-1.0.0.tar.gz.
File metadata
- Download URL: py_readonlyx-1.0.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb69ccd0c41c65a11398d81cd796c84ceb7f3b23d7df0827e38fb62461816291
|
|
| MD5 |
3dc4198f0164d7ce478cd0cce1bfadab
|
|
| BLAKE2b-256 |
0829a5969e10c7955203a0113d9cfbf39f94c6266f33330f3a5375d0c06bff03
|
File details
Details for the file py_readonlyx-1.0.0-py3-none-any.whl.
File metadata
- Download URL: py_readonlyx-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1cdde35ad5d612035cf9b579aee970cac71de904a5e57b3d59ddfce62499941
|
|
| MD5 |
e1dab149718725b776798d227ec3af44
|
|
| BLAKE2b-256 |
bc4c2fd1a0bbf6eb4ec6dafbbcd674e1590c3a659ccec53bbfe2f0d2be835840
|