Skip to main content

Python client for CaronaShow APIs

Project description

caronashow-api

Python client for CaronaShow APIs.

Installation

pip install caronashow-api

Usage

The code below is a minimal version and not comprehensive of all APIs.

To view the API definitions and types, consult the .protobuf files or generated code.

Pooler API client

import asyncio

from caronashow.pooler.v1.pooler_connect import PoolerServiceClient
from caronashow.pooler.v1.pooler_pb2 import (
    MATCHING_ALGORITHM_RANDOM,
    ExecuteMatchingAlgorithmOnDatasetRequest,
)


async def main():
    # Create a client
    client = PoolerServiceClient("http://localhost:8080")

    # Make a request
    request = ExecuteMatchingAlgorithmOnDatasetRequest(
        dataset_id="dataset-123",
        algorithm=MATCHING_ALGORITHM_RANDOM,
    )

    # Call the service
    response = await client.execute_matching_algorithm_on_dataset(request)
    print(response.operation)


if __name__ == "__main__":
    asyncio.run(main())

Pooler API server

from caronashow.pooler.v1.pooler_connect import (
    PoolerService,
    PoolerServiceASGIApplication,
)
from caronashow.pooler.v1.pooler_pb2 import (
    ExecuteMatchingAlgorithmOnDatasetResponse,
    Operation,
    OperationState,
)


class Pooler(PoolerService):
    async def execute_matching_algorithm_on_dataset(self, request, ctx):
        print("Request headers:", ctx.request_headers())
        response = ExecuteMatchingAlgorithmOnDatasetResponse(
            operation=Operation(
                operation_id="op-123",
                dataset_id=request.dataset_id,
                state=OperationState.OPERATION_STATE_SUCCEEDED,
            )
        )
        return response


app = PoolerServiceASGIApplication(Pooler())

Onboarding API client

import asyncio

from caronashow.service.v1.onboarding_connect import OnboardingServiceClient
from caronashow.service.v1.onboarding_pb2 import (
    CompleteOnboardingRequest,
    DriverOfferSetup,
    GetOnboardingStatusRequest,
)
from caronashow.types.v1.common_pb2 import TimeOfDay
from caronashow.types.v1.user_pb2 import PARTICIPATION_MODE_OFFER


async def main():
    client = OnboardingServiceClient("http://localhost:8080")

    status = await client.get_onboarding_status(GetOnboardingStatusRequest())
    if not status.onboarding_completed:
        response = await client.complete_onboarding(
            CompleteOnboardingRequest(
                enrolled_in_vulnerability_filter=False,
                terms_accepted=True,
                participation_mode=PARTICIPATION_MODE_OFFER,
                offer=DriverOfferSetup(
                    vehicle_model="Honda Fit 2019",
                    vehicle_color="Prata",
                    vehicle_plate="ABC-1234",
                    offered_seats=4,
                    origin_address="Rua Exemplo, 100",
                    departure_time=TimeOfDay(hours=7, minutes=30),
                    return_time=TimeOfDay(hours=18, minutes=0),
                    accepting_requests=True,
                ),
            )
        )


if __name__ == "__main__":
    asyncio.run(main())

Types

from caronashow.types.v1 import user_pb2, common_pb2

# Create user objects
user = user_pb2.User(...)

# Common types
time = common_pb2.TimeOfDay(hours=7, minutes=30)
chat_pref = common_pb2.CHAT_PREFERENCE_OPEN

License

MIT License - see LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

caronashow_api-0.8.0.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

caronashow_api-0.8.0-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

File details

Details for the file caronashow_api-0.8.0.tar.gz.

File metadata

  • Download URL: caronashow_api-0.8.0.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for caronashow_api-0.8.0.tar.gz
Algorithm Hash digest
SHA256 80909ec349155a16bdd8ed65541c19e6e80684f5b3958e8b7d8ebae325bb8238
MD5 5a8a267569f1a88dbc040fc27eb6c53c
BLAKE2b-256 fd74611fa825abd13c8ddb4fa56ab952ec4ccddeb89aae04076b5b585d3bb019

See more details on using hashes here.

File details

Details for the file caronashow_api-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: caronashow_api-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 33.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for caronashow_api-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d1883e7101882f0a9ae735fe6a9bfc9ba2772ca2208878f7e72ab2150a2f99d
MD5 db9e59e4944f3931cb218e268593614e
BLAKE2b-256 0c331ecfc5daac4e8ba0f113b8d7f64762b5ce63aebd3b2a9c5c662e55aedfd3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page