Skip to main content

Laka

Build Status codecov Codacy Badge PyPI - Python Version PyPI PyPI - License

Laka is a microservice framework for Python, based on json and redis.

Install

  1. Step one Install Fofo
  2. Step two
    pip install laka
    

Feature

  • Service Register and Discovery
  • Transmit data with Json RPC

Tutorial: Server

  1. Create Server and Register Service
    from laka import LakaServer
    
    laka_server = LakaServer(
        service_name="lakaTest",    # Register Service with this name
        redis_host="localhost", 
        redis_port=6379, 
        redis_queue="laka_request", 
        fofo_host="10.88.190.211",
        fofo_port=6379,
        response_message=RESPONSE_MESSAGE,
        check_health=True,
    )
    
  2. Define param for Handler
    from laka import Param
    
    class CreateUserParam(Param):
        def __init__(self):
            self.account = None
            self.password = None
            self.tel = None
        
        def validate(self):
            """
            validate will be run automatically
            you should not run validate by yourself
            """
            if not (self.account and self.password):
                return False
            return True
    
  3. Define Handler
    from laka import Handler
    
    class CreateUserHandler(Handler):
        Param = CreateUserParam
    
        def handle(self):
            user = {"password":self.param.password, "account":self.param.account}
            return HandlerOK(user)
    
  4. Add router
    # COMMAND_CREATE_USER = 101
    laka_server.router(COMMAND_CREATE_USER, CreateUserHandler)
    
  5. Accept & Handle request
    for queue, cmd in laka_server.accept_request():
        handler_response = laka_server.handle(cmd)
    

Tutorial: Client

  1. Create Client
    from laka import LakaClient
    
    laka_client = LakaClient(
        service_name="lakaTest",    # service_name is the service you want to connect to
        fofo_host="10.88.190.211",
        fofo_port=6379,
    )
    
  2. Define & Create param
    from laka import Param
    
    class CreateUserParam(Param):
        
        def __init__(self, account, password, tel=None):
            self.account = account
            self.password = password
            self.tel = tel
        
        def validate(self):
            """
            validate will be run in request automatically
            you should not run validate by yourself
            """
            if not (self.account and self.password):
                return False
            return True
    
    param = CreateUserParam("olivetree", "123456")
    
  3. Send Request
    request_id = laka_client.request(COMMAND_CREATE_USER, param)
    
  4. Get Response
    response = laka_client.accept_response(request_id)
    print("response = ", response.json())
    

Metadata

Release files for Laka 0.3

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

Source distribution (sdist)

Source distribution for Laka 0.3
File Size Uploaded Provenance
Laka-0.3.tar.gz 7.9 kB Without provenance Details

Release files / Laka-0.3.tar.gz

Download URL Laka-0.3.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e56ecd5cd7c386e8eb61696aa2cd6e08f2c7b9b9d711ebb281747e834177deba
BLAKE2b-256 checksum
How to use checksums
d4e64aa46d31ca4ca88a96ec2b09b9bbebde4012ed53b3f5c9cbd53884ab2463
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

Security for Laka 0.3

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