https://github.com/torokmark/esu
:egg: Enjoy the flexibility of structs with esu!
https://github.com/torokmark/esu
metaprogramming openstruct python struct
Last synced: 11 months ago
JSON representation
:egg: Enjoy the flexibility of structs with esu!
- Host: GitHub
- URL: https://github.com/torokmark/esu
- Owner: torokmark
- License: apache-2.0
- Created: 2019-10-20T16:47:02.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-10-27T05:43:12.000Z (over 6 years ago)
- Last Synced: 2025-05-29T20:02:04.944Z (about 1 year ago)
- Topics: metaprogramming, openstruct, python, struct
- Language: Python
- Homepage: https://esu.readthedocs.io/
- Size: 35.2 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Welcome to Esu Structs!
[](https://travis-ci.org/torokmark/esu)
[](https://esu.readthedocs.io/en/latest/)
[](https://pypi.org/project/esu/)
[](https://github.com/torokmark/esu)
[](https://github.com/torokmark/esu/blob/master/LICENSE.md)
Enjoy the flexibility of structs with *esu*!
You can create types on the fly with previously declared fields and methods by using *esu struct*.
The created type additionally contains methods for equation, hashing and string representation.
### Install
```sh
pip install esu
```
### Usage
#### Struct
```py
from esu import Struct
Customer = Struct(
'Customer',
'name', 'age',
methods={
'greeting': lambda self: "Hello {}".format(self.__dict__['name'])
})
dave = Customer()
dave.name = 'Dave'
dave.age = 25
dave.greeting() # => Hello Dave
anna = Customer('Anna', 28)
anna.greeting() # => Hello Anna
```
#### OpenStruct
```py
from esu import OpenStruct
bob = OpenStruct()
bob.name = Bob
bob.age = 54
print(bob) # => [name=Bob, age=54]
su = OpenStruct({'name': 'Su', 'gender': 'female'})
su.employed = True
print(su) # => [name=Su, gender=female, employed=True]
```
### Documentation
For further information, read the documentation that can be found: [https://esu.readthedocs.io](https://esu.readthedocs.io)
### Contribution
1. Fork it!
2. Make your changes!
3. Send a PR!