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.3.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.3-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cartons-1.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 9794bd4bbedd8501263c3487f2fce84bc2399412130a226eb40b6213584fee63
MD5 1a5706b320fdcb64aa84cf4b92baef82
BLAKE2b-256 1397347275f62a3308707c80eec67df26aad3adac4ef7ec113503e7070f9dc98

See more details on using hashes here.

Provenance

The following attestation bundles were made for cartons-1.0.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: cartons-1.0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1e92b80b7569708decf55339c59175ad5c33e02e0ca3f17a1cf25b96caf7ce20
MD5 d22a433d871eae224d2161297a22c009
BLAKE2b-256 ab85dd23083f348bdd135b034ae4ecae62aa26dabbef49c6ab701b3438f4f20a

See more details on using hashes here.

Provenance

The following attestation bundles were made for cartons-1.0.3-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