Skip to main content

Simple OSRM routing and Folium map drawing toolkit

Project description

cartons

A small Python toolkit for routing and map visualization.

cartons calculates routes using OSRM (via routingpy) and renders them on an interactive Leaflet map using folium.

With only a few lines of code you can compute a route between two coordinates and generate an HTML map displaying the route.

The library is designed to be simple, lightweight, and easy to integrate into scripts or small projects.


Demo

Live demo:

https://router.project-osrm.org

This public OSRM server is used in the examples to calculate routes.


Features

  • Simple interface for route calculation
  • Interactive map rendering
  • Uses the OSRM routing engine
  • Lightweight with minimal dependencies
  • Generates shareable HTML maps

Installation

cartons is available on PyPI.

Install from PyPI

pip install cartons

Install from source

git clone https://github.com/yourname/cartons.git
cd cartons
pip install -e .

Dependencies

  • routingpy
  • folium

These will be installed automatically when installing the package.


Quick Example

import cartons

m = cartons.draw(
    "https://router.project-osrm.org",
    8.5417, 47.3769,
    8.55, 47.38
)

m.save("route.html")

This generates an interactive HTML map showing the calculated route.

Open the generated file in a browser to view the map.


Project Structure

cartons/
├── routing.py
├── display.py
└── __init__.py

routing.py

Handles communication with the OSRM routing engine using routingpy.

It sends coordinates to the routing server and returns the routing response.


display.py

Responsible for rendering the route on a Leaflet map using folium.

OSRM returns coordinates in the format:

[lon, lat]

Since Folium expects [lat, lon], the coordinates are converted before drawing the route.


Public OSRM Server

Examples use the public OSRM demo server:

https://router.project-osrm.org

This server is suitable for:

  • testing
  • small scripts
  • experimentation

For production use, running your own OSRM server is recommended.


API

draw(base_url, lon1, lat1, lon2, lat2, col="blue", weight=5)

Calculate a route and return a folium.Map object.

Parameters

Parameter Description
base_url OSRM server URL
lon1 Start longitude
lat1 Start latitude
lon2 Destination longitude
lat2 Destination latitude
col Route color
weight Line thickness

Returns

folium.Map

Goals

cartons aims to provide:

  • a simple routing interface
  • quick map visualization
  • minimal dependencies
  • easy integration into Python scripts

License

MIT License

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

cartons-1.0.5.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

cartons-1.0.5-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file cartons-1.0.5.tar.gz.

File metadata

  • Download URL: cartons-1.0.5.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cartons-1.0.5.tar.gz
Algorithm Hash digest
SHA256 17ff5ebe712676dda1911eeabcea7e7202a438afa59fbda28c4363856b9957d3
MD5 e727fdefcf62452049a9f06441ec8642
BLAKE2b-256 4b6427a7a3d0ddc0ef80e453410ae6088b527881d09b863dcb84958ae705345c

See more details on using hashes here.

Provenance

The following attestation bundles were made for cartons-1.0.5.tar.gz:

Publisher: python-publish.yml on AndPan3/cartons

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cartons-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: cartons-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cartons-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 467ffbae545f3862a216186ad8d096b41b07f2504b368dc1e4158bd95c518b65
MD5 2d61b08a122f01b2bb573a2dbeda5128
BLAKE2b-256 fdefb959d85f8d3ea765369446aa0a7689a0bdf30feb650e9e1ee920e072d8da

See more details on using hashes here.

Provenance

The following attestation bundles were made for cartons-1.0.5-py3-none-any.whl:

Publisher: python-publish.yml on AndPan3/cartons

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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