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.0.0.tar.gz (9.1 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.0.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

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

Hashes for py_readonlyx-1.0.0.tar.gz
Algorithm Hash digest
SHA256 cb69ccd0c41c65a11398d81cd796c84ceb7f3b23d7df0827e38fb62461816291
MD5 3dc4198f0164d7ce478cd0cce1bfadab
BLAKE2b-256 0829a5969e10c7955203a0113d9cfbf39f94c6266f33330f3a5375d0c06bff03

See more details on using hashes here.

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

Hashes for py_readonlyx-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b1cdde35ad5d612035cf9b579aee970cac71de904a5e57b3d59ddfce62499941
MD5 e1dab149718725b776798d227ec3af44
BLAKE2b-256 bc4c2fd1a0bbf6eb4ec6dafbbcd674e1590c3a659ccec53bbfe2f0d2be835840

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