Skip to main content

Python++

PyPI Deployment Unit Tests

A robust Java-style OOP system for Python, with support for statics, encapsulation, and inheritance.

View on PyPI / Built by Kento Nishi and Ronak Badhe

Python++ allows Python programmers to use object oriented programming principles in Python.

Installation

The package is available on PyPI. You can install the package with the following command:

pip install pythonpp

Usage

Importing the Library

You can import Python++ with the following:

from pythonpp import *

Class Declaration

Declare Python++ classes with the @PythonPP decorator.

@PythonPP
class MyClass:
    pass # class code here

Namespace and Scopes

Declare variables and methods for Python++ classes within namespace.

@PythonPP
class MyClass:
    def namespace(public, private):
        pass # methods and variables here

Code within namespace has access to the following scopes:

Scope Description
public The public instance scope.
private The private instance scope.
public.static The public static scope.
private.static The private static scope.

Static Initializers

Declare static initializers for Python++ classes using the @staticinit decorator. Static initializers do not have access to instance variables and methods. Static initializers cannot have input parameters.

@PythonPP
class MyClass:
    def namespace(public, private):
        @staticinit
        def StaticInit():
            public.static.publicStaticVar = "Static variable (public)"
            private.static.privateStaticVar = "Static variable (private)"

Alternatively, static variables can be declared in the bare namespace if the variable assignments are constant. Using bare static variable declarations are not recommended.

Constructors

Constructors can be declared using the @constructor decorator. Constructors can have input parameters.

@PythonPP
class MyClass:
    def namespace(public, private):
        @constructor
        def Constructor(someValue):
            public.publicInstanceVar = "Instance variable (public)"
            public.userDefinedValue = someValue

Method Declarations

Methods are declared using the @method(scope) decorator with the public and private scopes in namespace.

@PythonPP
class MyClass:
    def namespace(public, private):
        @method(public)
        def publicMethod():
            pass # public instance method here

        @method(private)
        def privateMethod():
            pass # private instance method here

        @method(public.static)
        def publicStaticMethod():
            pass # public static method here

        @method(private.static)
        def privateStaticMethod():
            pass # private static method here

Special Methods

Declare special built-in methods using the @special decorator.

@PythonPP
class MyClass:
    def namespace(public, private):
        @special
        def __str__():
            return "Some string value"

Inheritance

Classes can extend other classes using standard Python class inheritance.

@PythonPP
class ParentClass:
    def namespace(public, private):
        @staticinit
        def StaticInit():
            public.static.staticVar = "Static variable"

        @constructor
        def Constructor(param):
            print("Parent constructor")
            public.param = param

@PythonPP
class ChildClass(ParentClass): # ChildClass extends ParentClass
    def namespace(public, private):
        @staticinit
        def StaticInit():
            ParentClass.staticinit() # Call parent static initializer
            public.static.staticVar2 = "Static variable 2"

        @constructor
        def Constructor(param):
            # Call parent constructor
            ParentClass.constructor(param)

Quickstart Example

from pythonpp import *

@PythonPP
class ParentClass:
    def namespace(public, private):
        @staticinit
        def StaticInit():
            public.static.publicStaticVar = "Public static variable"
            private.static.privateStaticVar = "Private static variable"

        @constructor
        def Constructor(parameter):
            private.privateVariable = parameter

@PythonPP
class ChildClass(ParentClass):
    def namespace(public, private):
        @staticinit
        def StaticInit():
            ParentClass.staticinit()

        @constructor
        def Constructor(parameter):
            ParentClass.constructor(parameter)
            public.publicVariable = "Public variable"
            private.privateVariable = "Private variable"

        @method(public)
        def getPrivateVariable():
            return private.privateVariable

        @method(public.static)
        def getPrivateStaticVar():
            return private.static.privateStaticVar

        @special
        def __str__():
            return "ChildClass object"
print(ChildClass.publicStaticVar)
# > Private static variable
print(ChildClass.getPrivateStaticVar())
# > Private static variable

obj = ChildClass("Parameter value")
print(obj)
# > ChildClass object
print(obj.publicVariable)
# > Public variable
print(obj.getPrivateVariable())
# > Parameter value
try:
    obj.privateVariable # results in an error
except Exception as e:
    print(e)
# > 'ChildClass' object has no attribute 'privateVariable'

Full Example

You can view the full example Jupyter notebook here.

Metadata

Release files for pythonpp 2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pythonpp 2.2
File Size Uploaded Provenance Actions
pythonpp-2.2.tar.gz 6.2 kB Without provenance Details for pythonpp-2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pythonpp 2.2
File Interpreter ABI Platform Actions
pythonpp-2.2-py3-none-any.whl Python 3 none any Details for pythonpp-2.2-py3-none-any.whl

Total release size: 12.2 kB

Release files / pythonpp-2.2.tar.gz

Download URL pythonpp-2.2.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d023b372c49619515290a985016489a68c16d0ab3a1a7fc4c9d14f1e51b9af5e
BLAKE2b-256 checksum
How to use checksums
440de31e50e53422b41b2639c09a2b38ec027f25dea74010ee628bec3b6ec30a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

Release files / pythonpp-2.2-py3-none-any.whl

Download URL pythonpp-2.2-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4d0878398a928adca479a13738384608f54a6bebc8f7e56e72bde0f03082180f
BLAKE2b-256 checksum
How to use checksums
fb931010a57f4647efb50224eb40eb6d51d59dc409388ebe18f2c0548aee1f7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

Security for pythonpp 2.2

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page