free_properties
What is free_properties?
free_properties is a python package that features the FreeProperty class. A FreePropety object behaves just like its value property, allowing it to be used as a proxy for get, and set calculations like a python property.
Installation
Get the latest version of free_properties from https://pypi.python.org/pypi/free_properties/
If you have an installation of Python with pip, simple install it with:
$ pip install free_properties
To get the git version, run:
$ git clone git://github.com/yoelcortes/free_properties
Documentation
free_properties’s documentation is available on the web:
Getting started
The PropertyFactory is a FreeProperty class creator that functions similar to Python ‘property’ objects. Use the PropertyFactory to create a Weight class which calculates weight based on density and volume:
>>> from free_properties import PropertyFactory
>>> def getter(self):
... '''Weight (kg) based on volume (m^3).'''
... data = self.data
... rho = data['rho'] # Density (kg/m^3)
... vol = data['vol'] # Volume (m^3)
... return rho * vol
>>>
>>> def setter(self, weight):
... data = self.data
... rho = data['rho'] # Density (kg/m^3)
... data['vol'] = weight / rho
>>>
>>> # Initialize with a value getter, setter, and the class name.
>>> Weight = PropertyFactory(getter, setter, 'Weight', units='kg')
It is more convinient to use the PropertyFactory as a decorator:
>>> @PropertyFactory(units='kg')
>>> def Weight(self):
... '''Weight (kg) based on volume (m^3).'''
... data = self.data
... rho = data['rho'] # Density (kg/m^3)
... vol = data['vol'] # Volume (m^3)
... return rho * vol
>>>
>>> @Weight.setter
>>> def Weight(self, weight):
... data = self.data
... rho = data['rho'] # Density (kg/m^3)
... data['vol'] = weight / rho
Create dictionaries of data and initialize new Weight objects:
>>> water_data = {'rho': 1000, 'vol': 3}
>>> ethanol_data = {'rho': 789, 'vol': 3}
>>> weight_water = Weight('Water', water_data)
>>> weight_ethanol = Weight('Ethanol', ethanol_data)
>>> weight_water
<Water: 3000 kg>
>>> weight_ethanol
<Ethanol: 2367 kg>
These properties behave just like their dynamic value:
>>> weight_water + 30
3030
>>> weight_water + weight_ethanol
5367
Get and set the value through the ‘value’ attribute:
>>> weight_water.value
3000
>>> weight_water.value = 4000
>>> weight_water.value
4000
>>> water_data # Note that the volume changed too
{'rho': 1000, 'vol': 4}
In place magic methods will also change the property value:
>>> weight_water -= 1000
>>> weight_water
<Weight(Water): 3000 kg>
>>> water_data # The change also affects the original data
{'rho': 1000, 'vol': 3}
Use the property_array to manage free properties as an array:
>>> from free_properties import property_array
>>> prop_arr = property_array([weight_water, weight_ethanol])
>>> prop_arr
property_array([3000.0, 2367.0], dtype=object)
>>> prop_arr.sum()
5367.0
Changing the values of a property_array changes the value of its properties:
>>> # Addition in place
>>> prop_arr += 3000
>>> prop_arr
property_array([6000.0, 5367.0], dtype=object)
>>> # Note how the data also changes
>>> water_data
{'rho': 1000, 'vol': 6.0}
>>> ethanol_data
{'rho': 789, 'vol': 6.802281368821292}
>>> # Setting an item changes the property value
>>> prop_arr[1] = 2367
>>> ethanol_data
{'rho': 789, 'vol': 3}
New arrays have no connection to the property_array:
>>> prop_arr - 1000 # Returns a new array
array([5000.0, 1367.0], dtype=object)
>>> water_data # Data remains unchanged
{'rho': 1000, 'vol': 6.0}
Latest source code
The latest development version of free_properties’s sources can be obtained at:
Bug reports
To report bugs, please use the free_properties’ Bug Tracker at:
License information
See LICENSE.txt for information on the terms & conditions for usage of this software, and a DISCLAIMER OF ALL WARRANTIES.
Although not required by the free_properties’ license, if it is convenient for you, please cite free_properties if used in your work. Please also consider contributing any changes you make back, and benefit the community.
Citation
To cite free_properties in publications use:
Yoel Cortes-Pena (2019). free_properties: Manage properties outside a class. https://github.com/yoelcortes/free_properties
Metadata
Release files for free-properties 0.3.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| free_properties-0.3.6.tar.gz | 9.2 kB | Without provenance | Details for free_properties-0.3.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| free_properties-0.3.6-py3-none-any.whl | Python 3 | none | any | Details for free_properties-0.3.6-py3-none-any.whl |
Total release size: 18.8 kB
Release files / free_properties-0.3.6.tar.gz
| Download URL | free_properties-0.3.6.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
27a65ca4ac30eee2aeec90b74857afcdcf01e4eb7b2e112891db9bb8b01a9fe0
|
|
BLAKE2b-256 checksum How to use checksums |
a4e36504ea8fd76ec48fc9e50f6fcae94f795c1773b2308aabeb441b51ee1b96
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.12
|
Release files / free_properties-0.3.6-py3-none-any.whl
| Download URL | free_properties-0.3.6-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3c5ee013e6a74f46d7232824fb499428c9f40f1b4efd6cd8c34510e91d65a381
|
|
BLAKE2b-256 checksum How to use checksums |
76159115abafa5a7e94dd7178d20067d5d1998d773c06493d2012d4d1d80ec76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.12
|
Security for free-properties 0.3.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.