https://github.com/redodo/formats
Support multiple formats with ease.
https://github.com/redodo/formats
Last synced: about 1 year ago
JSON representation
Support multiple formats with ease.
- Host: GitHub
- URL: https://github.com/redodo/formats
- Owner: redodo
- License: mit
- Created: 2014-12-13T14:16:42.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-02-11T21:30:25.000Z (over 11 years ago)
- Last Synced: 2025-02-06T05:34:30.755Z (over 1 year ago)
- Language: Python
- Size: 172 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Formats
=======
[
](https://pypi.python.org/pypi/formats)
[
](https://github.com/redodo/formats/blob/master/LICENSE)
*Support multiple formats with ease.*
Installation via PIP:
```bash
pip install --pre formats
```
Quick usage overview:
```python
>>> import formats
>>> formats.discover()
>>> text = '''
... awesome_things:
... - dodos
... - pythons
... '''
>>> formats.parse('yaml', text)
{'awesome_things': ['dodos', 'pythons']}
>>> formats.convert('yaml', 'json', text)
'{"awesome_things": ["dodos", "pythons"]}'
```
The Basics
----------
Formats will provide you with a consistent API to parse and compose
data.
Registering new formats
-----------------------
```python
import formats
import someformat
formats.register('someformat', someformat.loads, someformat.dumps)
# or
formats.register_parser('someformat', someformat.loads)
formats.register_composer('someformat', someformat.dumps)
```
Creating your own formats
-------------------------
You could of course use the `register` method to register your own
parser, but decorators are much more fun!
```python
import formats
@formats.parser('text')
def text_parser(text):
return text
@formats.composer('text')
def text_composer(text):
return text
```