Skip to main content

ElasticObjects introduces the concept of 'elastic objects' in Python - a flexible approach to object-oriented programming.

Project description

LiquidPy

alt text

LiquidPy introduces the concept of "liquid objects" in Python - a flexible approach to object-oriented programming that allows for dynamic attribute assignment and management at runtime.

Features

  • Dynamic attribute addition and removal
  • Flexible object initialization
  • Transparent attribute access
  • Ideal for handling evolving data structures, configuration management, and API integrations

Installation

You can install LiquidPy using pip:

pip install liquidpy

Usage

Basic Usage

from liquidpy.liquid_object import LiquidObject

# Create a new liquid object
person = LiquidObject()

# Add attributes dynamically
person.name = "Alice"
person.age = 30

# Access attributes
print(person.name)  # Output: Alice
print(person.age)   # Output: 30

# Add a method
person.greet = lambda: f"Hello, I'm {person.name}!"
print(person.greet())  # Output: Hello, I'm Alice!

# Remove an attribute
del person.age

# Trying to access a removed attribute raises an AttributeError
# print(person.age)  # This would raise an AttributeError

Initialization with Attributes

# Initialize with attributes
config = LiquidObject(
    database="mysql",
    host="localhost",
    port=3306
)

print(config.database)  # Output: mysql
print(config.port)      # Output: 3306

# Add new attributes later
config.username = "admin"

Use Case: Handling API Responses

import requests
from liquidpy import LiquidObject

def get_user_data(user_id):
    # Simulating an API call
    response = requests.get(f"https://api.example.com/users/{user_id}")
    data = response.json()
    
    # Create a liquid object from the response
    user = LiquidObject(**data)
    
    return user

# Usage
user = get_user_data(123)
print(user.name)
print(user.email)

# If the API starts returning a new field, it's automatically accessible
print(user.new_field)  # No need to update the class definition

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

elastic_objects-0.1.1.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

elastic_objects-0.1.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file elastic_objects-0.1.1.tar.gz.

File metadata

  • Download URL: elastic_objects-0.1.1.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.8

File hashes

Hashes for elastic_objects-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9bf87fa765ab735aa9a565163ba4595403fca609810c274a814420ab8314cc60
MD5 3245b2c3fe0360f7d0cf3d351e8daac2
BLAKE2b-256 dd13a954ae14afe3416800d3662bf57e0691eeb6a34ba997692e49a90bddc160

See more details on using hashes here.

File details

Details for the file elastic_objects-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for elastic_objects-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 60a7f4aa8b3b6b88e9a30ec4047e6bfa04d21714eedba887cfb51bb95f2fb8b2
MD5 022b4a3145c8d680af0e2e2aab9aee1d
BLAKE2b-256 e671628d840fdd6d7237e4a80be5f2e517565c610187f17176116da6fa32f231

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