Slim. Beautiful. Snaked.
This package is also available for JavaScript on NPM as snaked-js.
Snaked - Snakifying Your Code For PEP8
snaked-py is a universal wrapper for Python objects of all kinds.
It allows you to access camelCase and PascalCase attributes of wrapped objects using
the familiar, and officially approved by the Python Software Foundation, snake_case syntax.
Installation
You can install the latest stable release of snaked-py using pip:
$ pip install snaked-py
You can also clone the GitHub repository and install the package manually by running:
$ python3 setup.py install
Features
- auto-enables snake_case access for camelCase objects
- autp-enables snake_case access for PascalCase objects
- wraps around any kind of object/3rd-party module/etc.
- includes runtime optimizations like caching
- PEP8-compliant and lightweight with only one dependency
Why should I use Snaked?
PEP8 (Python Enhancement Proposal 8, the official definition of Python coding standards) proposes the use of snake_case syntax throughout your code. However, it also states that consistency has more preference compared to PEP8 compliance.
If a 3rd-party module uses camelCase while you stick to to the official snake_case, you will have inconsistent code syntax which violates the PEP8. Using camelCase for all your code however, doesn't fully comply with PEP8 either.
Snaked solves this problem by providing convenient wrapper utilities for accessing your
camelCase objects using the preferred snake_case syntax.
Example Usage
Let's use the following class in this example:
class Camel(object):
def createMe(self, name):
self.name = name
def sayHello(self):
print("Hey, I'm", self.name)
Usual access:
>>> animal = Camel()
>>> animal.createMe("Mr. C. Java")
>>> animal.sayHello()
Hey, I'm Mr. C. Java
Snaked Access:
>>> from snaked import Snaked
>>> animal = Snaked(Camel())
>>> animal.create_me("Mr. C. Python")
>>> animal.say_hello()
Hey, I'm Mr. C. Python
Edge Cases
Snaked uses resolution-caching by default to improve performance. In some rare situations, you might remove camelCase/pascalCase-attributes of your wrapped objects and re-introduce them in a different case.
Example:
>>> original = Camel()
>>> animal = Snaked(original)
>>> animal.create_me("Mr. Ed")
>>> animal.say_hello()
Hey, I'm Mr. Ed
>>> original.SayHello = original.sayHello
>>> del original.sayHello
>>> animal.say_hello()
AttributeError: 'Camel' object has no attribute 'sayHello'
You will then have to clear the resolution cache to let Snaked search again for the corresponding new camelCase/PascalCase/snake_case version:
>>> original.SayHello = original.sayHello
>>> del original.sayHello
>>> from snaked import clear_cache
>>> clear_cache(animal)
>>> animal.say_hello()
Hey, I'm Mr. Ed
You can also circumvent this situation by preventing Snaked from caching resolved attributes. Note however, that this will decrease your program's performance drastically.
animal = Snaked(original, use_cache=False)
License
This project is licensed under the MIT license by Squirrel-Preslash. It is free to use for any commercial or non-commercial purpose.
If you do so, you are required to include the full license text in a special section of your compiled program (i.e. in a credits or startup screen) or a copy of the license in the distributed source code.
Metadata
Release files for snaked-py 1.0.1
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 |
|---|---|---|---|---|
| snaked-py-1.0.1.tar.gz | 4.0 kB | Without provenance | Details for snaked-py-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| snaked_py-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for snaked_py-1.0.1-py3-none-any.whl |
Total release size: 8.8 kB
Release files / snaked-py-1.0.1.tar.gz
| Download URL | snaked-py-1.0.1.tar.gz |
|---|---|
| Size | 4.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ab25cb0eec5f816706fde1b07ba54e1d310bbceaf1d43da6fca5cd0e32e8b657
|
|
BLAKE2b-256 checksum How to use checksums |
4de286aef64408e01ef25be548acbb9c58da03698dcc00adea84305608c3ecac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9
|
Release files / snaked_py-1.0.1-py3-none-any.whl
| Download URL | snaked_py-1.0.1-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d64def77f74c651240faf7d4e3ec234e86adb30ddcdd3bf30dba875455662cf9
|
|
BLAKE2b-256 checksum How to use checksums |
6051b08bdce09b0fdedae5677a850e1fd2eac3225d145d156e0a7ea862927f0f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.9
|
Security for snaked-py 1.0.1
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.