sugar.py¶
Python utility library. Based on sugar Javascript Library.
Links¶
- Project: https://github.com/bharadwajyarlagadda/sugar.py
- Documentation: http://sugarpy.readthedocs.io
- Pypi: https://pypi.python.org/pypi/sugar.py
- TravisCI: https://travis-ci.org/bharadwajyarlagadda/sugar.py
Features¶
- Supported on Python 2.7 and Python 3.3+.
Quickstart¶
Install using pip:
pip install sugar.py
>>> import sugar
>>> float(sugar.average([1, 2, 3]))
2.0
>>> sugar.construct(4, lambda x: x * 2)
[0, 2, 4, 6]
>>> sugar.count([1, 2, 3, 3], 3)
2
>>> sugar.subtract([1, 2, 3], 2)
[1, 3]
>>> sugar.subtract ([1, 2, 3], [1, 3])
[2]
>>> sugar.subtract([1, 2, 3], 4)
[1, 2, 3]
Guide¶
Installation¶
sugar.py requires Python 2.7 or 3.3+.
To install from PyPI:
pip install sugar.py
You can also install sugar.py with all the latest changes:
$ git clone git@github.com:bharadwajyarlagadda/sugar.py.git
$ cd sugar.py
$ python setup.py install
API Reference¶
-
sugar.arrays.
average
(array)[source]¶ Returns the average for all the values in the given
array
.Parameters: array (list) – List of values. Returns: Average of all the values in the given list. Return type: int/float Example
>>> float(average([1, 2, 3])) 2.0
New in version 0.1.0.
-
sugar.arrays.
construct
(var, callback)[source]¶ Constructs an array of
var
length from the values ofcallback
.Parameters: - var (int) – Length of the array intended.
- callback – A method that can take in each variable from the given range and return back a new value based on the method definition.
Returns: A list of
callback
values.Return type: list
Example
>>> construct(4, lambda x: x * 2) [0, 2, 4, 6]
New in version 0.1.0.
-
sugar.arrays.
count
(array, value)[source]¶ Counts all elements in the
array
that match the givenvalue
.Parameters: - array (list) – A list of values provided by the user to search for.
- value (int/float/str) – Value that needs to be counted.
Returns: Count of the given value.
Return type: int
Example
>>> count([1, 2, 3, 3], 3) 2
New in version 0.1.0.
-
sugar.arrays.
subtract
(array, item)[source]¶ Subtracts
item
from thearray
and returns the result as a new array. Ifitem
is also an array, all elements in it will be removed.Parameters: - array (list) – A list of values provided by the user.
- item (list/int/float/str) – A value that needs to be removed from
array
.
Returns: A new list with the
item
removed.Return type: list
Example
>>> subtract([1, 2, 3], 2) [1, 3] >>> subtract ([1, 2, 3], [1, 3]) [2] >>> subtract([1, 2, 3], 4) [1, 2, 3]
New in version 0.1.0.
Project Info¶
License¶
MIT License
Copyright (c) 2016, Bharadwaj Yarlagadda
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Versioning¶
This project follows Semantic Versioning.
It is recommended to only use or import objects from the main module, sugar.py.
Changelog¶
v0.1.1 (2016-10-10)¶
FIX
: Added description for the package insetup.py
.FIX
: Added keywords insetup.py
.
v0.1.0 (2016-10-10)¶
- First release.
- Add
average()
. - Add
construct()
. - Add
count()
. - Add
subtract()
.
Authors¶
Lead¶
- Bharadwaj Yarlagadda, yarlagaddabharadwaj@gmail.com, bharadwajyarlagadda@github
Contributing¶
Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.
You can contribute in many ways:
Types of Contributions¶
Report Bugs¶
Report bugs at https://github.com/bharadwajyarlagadda/sugar.py.
If you are reporting a bug, please include:
- Your operating system name and version.
- Any details about your local setup that might be helpful in troubleshooting.
- Detailed steps to reproduce the bug.
Fix Bugs¶
Look through the GitHub issues for bugs. Anything tagged with “bug” is open to whoever wants to implement it.
Implement Features¶
Look through the GitHub issues for features. Anything tagged with “enhancement” or “help wanted” is open to whoever wants to implement it.
Write Documentation¶
sugar.py could always use more documentation, whether as part of the official sugar.py docs, in docstrings, or even on the web in blog posts, articles, and such.
Submit Feedback¶
The best way to send feedback is to file an issue at https://github.com/bharadwajyarlagadda/sugar.py.
If you are proposing a feature:
- Explain in detail how it would work.
- Keep the scope as narrow as possible, to make it easier to implement.
- Remember that this is a volunteer-driven project, and that contributions are welcome :)
Get Started!¶
Ready to contribute? Here’s how to set up sugar.py
for local development.
Fork the
sugar.py
repo on GitHub.Pull your fork locally:
$ git clone git@github.com:<username>/sugar.py.git
Install your local copy into a virtualenv. Assuming you have virtualenv installed, this is how you set up your fork for local development:
$ cd sugar.py/ $ pip install -r requirements-dev.txt
Create a branch for local development:
$ git checkout -b name-of-your-bugfix-or-feature
Now you can make your changes locally.
When you’re done making changes, check that your changes pass linting and all unit tests by testing with tox across all supported Python versions:
$ invoke tox
Add yourself to
AUTHORS.rst
.Commit your changes and push your branch to GitHub:
$ git add . $ git commit -m "Detailed description of your changes." $ git push origin name-of-your-bugfix-or-feature
Submit a pull request through the GitHub website.
Pull Request Guidelines¶
Before you submit a pull request, check that it meets these guidelines:
- The pull request should include tests.
- If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the README.rst.
- The pull request should work for Python 2.7, 3.4, and 3.5. Check https://travis-ci.org/bharadwajyarlagadda/sugar.py/pull_requests and make sure that the tests pass for all supported Python versions.