gabiteodoru-sugar


Namegabiteodoru-sugar JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/gabiteodoru/sugar
SummaryGabi's syntactic sugar & other utils
upload_time2025-07-16 04:50:20
maintainerNone
docs_urlNone
authorGabi Teodoru
requires_python>=3.7
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Sugar: Python Syntactic Sugar

A lightweight utility package that provides syntactic sugar and data manipulation tools to make Python code more concise and expressive.

## Installation

```bash
pip install git+https://github.com/gabiteodoru/sugar.git
```

Dependencies:
- pandas
- more_itertools

## Features

### Core Functions

- **Mapping Functions**: 
  - `imap`: List version of `map()`
  - `timap`: Tuple version of `map()`
  - `izip`: List version of `zip()`
  - `ifilter`: List version of `filter()`
  - `dmap`: Apply function to dictionary values
  - `dfilter`: Filter dictionary keys based on values
  - `flatten`: Flatten nested lists
  - `unique`: Return unique values from a list
- **Function Wrappers**: Operations using subtraction syntax
- **Smart String Splitting**: Handle nested brackets, quotes and special characters
- **Data Structure Manipulation**: Functions for dictionaries, lists and pandas DataFrames
- **Concise Data Access**: Simplified syntax for common operations

### Examples

```python
from sugar import *

# List operations
imap(lambda x: x+2, [2, 3, 4])  # [4, 5, 6]
timap(lambda x: x+2, [2, 3, 4])  # (4, 5, 6)
izip([1, 2], ['a', 'b'])        # [(1, 'a'), (2, 'b')]
ifilter(lambda x: x > 2, [1, 2, 3, 4])  # [3, 4]
flatten([[1, 2], [3, 4]])       # [1, 2, 3, 4]
unique([1, 2, 2, 3, 3])         # [1, 2, 3]

# Dictionary operations
dmap(lambda x: x*2, {'a': 1, 'b': 2})  # {'a': 2, 'b': 4}
dfilter(lambda x: x > 1, {'a': 1, 'b': 2, 'c': 3})  # ['b', 'c']

# String splitting
'a, b, c'-spl                   # ['a', 'b', 'c']
'a b c'-spls                    # ['a', 'b', 'c']
'a>b>c'-splon('>')              # ['a', 'b', 'c']
'a b c'-spls-first              # 'a'
'a b c'-spls-last               # 'c'

# Dictionary operations
'a:x, b:y, c:z'-spld            # {'a': 'x', 'b': 'y', 'c': 'z'}
'a:x, b:y, c:z'-spld-flipDict   # {'x': 'a', 'y': 'b', 'z': 'c'}

# Condition building
'a==1, b==2'-spland             # '(a==1)&(b==2)'

# DataFrame operations
df = pd.DataFrame({'x':'a, a, b'-spl, 'y':'c, d, d'-spl, 'z':[1, 2, 3]})
isUnique(df)                    # True
qselect(df,'y, colX:x')         # DataFrame with columns 'y' and 'colX' (renamed from 'x')
frontCols(df, 'y, z')           # DataFrame with columns reordered as ['y', 'z', 'x']
```

### Advanced Features

#### Script Execution

Run Python scripts in the current namespace:

```python
# Execute a script in the current namespace
eval(runpy)('script.py')
```

#### Function Application Syntax

Replace verbose function definitions with concise string expressions:

```python
# Traditional approach
def f(x):
    d = {}
    d['v'] = x.v.sum()
    d['dv'] = (x.v*x.c).sum()
    return pd.Series(d, index=['v', 'dv'])

rawData.groupby('s').apply(f)

# With sugar
rawData.groupby('s').apply('v: x.v.sum(), dv: (x.v*x.c).sum()'-fapply)
```

#### Data Classes

- `FriendlyDataClass`: Base class with dictionary-like access
- `Obj`: Enhanced dictionary with attribute access

#### Nested Structure Creation

```python
createNestedStruct('a, b, c', 'x, y', init=[1, 2, 3])
# Creates nested dictionary structure with leaf nodes [1, 2, 3]
```

## Contributing

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

## License

[MIT License](LICENSE)

## Documentation

Documentation generated with assistance from Claude (Anthropic).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/gabiteodoru/sugar",
    "name": "gabiteodoru-sugar",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": null,
    "author": "Gabi Teodoru",
    "author_email": "gabiteodoru@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ea/86/763b203ce83fcac1dccff6a102452f83ac5ac006ad42ed478c2e35e9f812/gabiteodoru_sugar-0.1.0.tar.gz",
    "platform": null,
    "description": "# Sugar: Python Syntactic Sugar\n\nA lightweight utility package that provides syntactic sugar and data manipulation tools to make Python code more concise and expressive.\n\n## Installation\n\n```bash\npip install git+https://github.com/gabiteodoru/sugar.git\n```\n\nDependencies:\n- pandas\n- more_itertools\n\n## Features\n\n### Core Functions\n\n- **Mapping Functions**: \n  - `imap`: List version of `map()`\n  - `timap`: Tuple version of `map()`\n  - `izip`: List version of `zip()`\n  - `ifilter`: List version of `filter()`\n  - `dmap`: Apply function to dictionary values\n  - `dfilter`: Filter dictionary keys based on values\n  - `flatten`: Flatten nested lists\n  - `unique`: Return unique values from a list\n- **Function Wrappers**: Operations using subtraction syntax\n- **Smart String Splitting**: Handle nested brackets, quotes and special characters\n- **Data Structure Manipulation**: Functions for dictionaries, lists and pandas DataFrames\n- **Concise Data Access**: Simplified syntax for common operations\n\n### Examples\n\n```python\nfrom sugar import *\n\n# List operations\nimap(lambda x: x+2, [2, 3, 4])  # [4, 5, 6]\ntimap(lambda x: x+2, [2, 3, 4])  # (4, 5, 6)\nizip([1, 2], ['a', 'b'])        # [(1, 'a'), (2, 'b')]\nifilter(lambda x: x > 2, [1, 2, 3, 4])  # [3, 4]\nflatten([[1, 2], [3, 4]])       # [1, 2, 3, 4]\nunique([1, 2, 2, 3, 3])         # [1, 2, 3]\n\n# Dictionary operations\ndmap(lambda x: x*2, {'a': 1, 'b': 2})  # {'a': 2, 'b': 4}\ndfilter(lambda x: x > 1, {'a': 1, 'b': 2, 'c': 3})  # ['b', 'c']\n\n# String splitting\n'a, b, c'-spl                   # ['a', 'b', 'c']\n'a b c'-spls                    # ['a', 'b', 'c']\n'a>b>c'-splon('>')              # ['a', 'b', 'c']\n'a b c'-spls-first              # 'a'\n'a b c'-spls-last               # 'c'\n\n# Dictionary operations\n'a:x, b:y, c:z'-spld            # {'a': 'x', 'b': 'y', 'c': 'z'}\n'a:x, b:y, c:z'-spld-flipDict   # {'x': 'a', 'y': 'b', 'z': 'c'}\n\n# Condition building\n'a==1, b==2'-spland             # '(a==1)&(b==2)'\n\n# DataFrame operations\ndf = pd.DataFrame({'x':'a, a, b'-spl, 'y':'c, d, d'-spl, 'z':[1, 2, 3]})\nisUnique(df)                    # True\nqselect(df,'y, colX:x')         # DataFrame with columns 'y' and 'colX' (renamed from 'x')\nfrontCols(df, 'y, z')           # DataFrame with columns reordered as ['y', 'z', 'x']\n```\n\n### Advanced Features\n\n#### Script Execution\n\nRun Python scripts in the current namespace:\n\n```python\n# Execute a script in the current namespace\neval(runpy)('script.py')\n```\n\n#### Function Application Syntax\n\nReplace verbose function definitions with concise string expressions:\n\n```python\n# Traditional approach\ndef f(x):\n    d = {}\n    d['v'] = x.v.sum()\n    d['dv'] = (x.v*x.c).sum()\n    return pd.Series(d, index=['v', 'dv'])\n\nrawData.groupby('s').apply(f)\n\n# With sugar\nrawData.groupby('s').apply('v: x.v.sum(), dv: (x.v*x.c).sum()'-fapply)\n```\n\n#### Data Classes\n\n- `FriendlyDataClass`: Base class with dictionary-like access\n- `Obj`: Enhanced dictionary with attribute access\n\n#### Nested Structure Creation\n\n```python\ncreateNestedStruct('a, b, c', 'x, y', init=[1, 2, 3])\n# Creates nested dictionary structure with leaf nodes [1, 2, 3]\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\n[MIT License](LICENSE)\n\n## Documentation\n\nDocumentation generated with assistance from Claude (Anthropic).\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Gabi's syntactic sugar & other utils",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/gabiteodoru/sugar"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "da5b440aca6307c513b95092674c7c88a75f82702bb34b01a087ef9d67b2e8b8",
                "md5": "f860f6ec902b923ba4c4011905832c7e",
                "sha256": "bcfa55120c50050a4591e1b4e6d3fd981d216e2915caee553b9e940c83cb1e9f"
            },
            "downloads": -1,
            "filename": "gabiteodoru_sugar-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f860f6ec902b923ba4c4011905832c7e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7798,
            "upload_time": "2025-07-16T04:50:19",
            "upload_time_iso_8601": "2025-07-16T04:50:19.031055Z",
            "url": "https://files.pythonhosted.org/packages/da/5b/440aca6307c513b95092674c7c88a75f82702bb34b01a087ef9d67b2e8b8/gabiteodoru_sugar-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ea86763b203ce83fcac1dccff6a102452f83ac5ac006ad42ed478c2e35e9f812",
                "md5": "daa8d2b4a5a9f7e5c6f87f97d94c8a7e",
                "sha256": "3307978c3fd61cbd28ab31a5842c77ad13625cc3b5cdb1c7a614d950c176c995"
            },
            "downloads": -1,
            "filename": "gabiteodoru_sugar-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "daa8d2b4a5a9f7e5c6f87f97d94c8a7e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 7133,
            "upload_time": "2025-07-16T04:50:20",
            "upload_time_iso_8601": "2025-07-16T04:50:20.236684Z",
            "url": "https://files.pythonhosted.org/packages/ea/86/763b203ce83fcac1dccff6a102452f83ac5ac006ad42ed478c2e35e9f812/gabiteodoru_sugar-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-16 04:50:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "gabiteodoru",
    "github_project": "sugar",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "gabiteodoru-sugar"
}
        
Elapsed time: 0.76471s