Skip to main content

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

Python License Dependencies Threading

Status Version Maintained


📖 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 @readonly ekleyin, 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

  1. Fork edin
  2. Feature branch oluşturun (git checkout -b feature/amazing-feature)
  3. Commit edin (git commit -m 'Add amazing feature')
  4. Push edin (git push origin feature/amazing-feature)
  5. 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
    • @readonly decorator
    • ReadOnlyError exception
    • Tam test coverage

⭐ Beğendiyseniz yıldız vermeyi unutmayın!
Created by ❤️ firatmio

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_readonlyx-1.6.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_readonlyx-1.6.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file py_readonlyx-1.6.0.tar.gz.

File metadata

  • Download URL: py_readonlyx-1.6.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for py_readonlyx-1.6.0.tar.gz
Algorithm Hash digest
SHA256 c0f551f344d69742896df786585983d22180d2e09b598caf244a032e4acf934a
MD5 b346b4ad48261c5382b59f5299bbf79f
BLAKE2b-256 eaba8eff5bc4d46c0df11450593cdf940a8c4d1d9fee805fcb57b8515de3c154

See more details on using hashes here.

File details

Details for the file py_readonlyx-1.6.0-py3-none-any.whl.

File metadata

  • Download URL: py_readonlyx-1.6.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

Hashes for py_readonlyx-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cc39a9d04d79837313d7064490a6087a02f330f185a1d596d7bce23534527e21
MD5 ee9453dd5295c6aa2ab8df48fb06ffdc
BLAKE2b-256 7d385f8362bc2b5e8b5b88c3f2ad599f5156a475f88b5e89c9f3f4fab5bba015

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page