Python library to retrieve historical and intraday data from Casablanca Stock Exchange via Medias24 API with Cloudflare bypass
Project description
casased
casased — Casablanca Stock Exchange Data Retriever
A Python library to retrieve historical and intraday data from the Casablanca Stock Exchange (Bourse de Casablanca) using the Medias24 API.
Features
- 📈 Historical Data: Daily OHLCV data for all listed stocks
- 📊 Index Data: MASI and MSI20 historical data
- ⏱️ Intraday Data: Real-time intraday prices
- 🏦 Multiple Assets: Load data for multiple stocks at once
- ⚖️ Index Weights: Market index weights (pondération)
- 🔤 Asset Aliases: Support for common ticker aliases (CFG, CMG, IAM, MDP, SAM)
Note: Some features (getCours, getKeyIndicators, getDividend, getIndex, getIndexRecap) are temporarily unavailable due to website changes. See ROADMAP.md for details.
Installation
pip install casased
Cloudflare Bypass (Optional)
If you encounter 403 errors due to Cloudflare protection, install browser automation tools:
# Install with browser automation support
pip install casased[cloudflare]
# Or install manually
pip install nodriver seleniumbase
The library will automatically use headless browser automation as a fallback when direct API requests fail.
Quick Start
import casased as cas
# List available assets
assets = cas.notation()
# Get historical data for a stock
df = cas.get_history('BCP', start='2024-01-01', end='2024-12-31')
# Get MASI index history
masi = cas.get_history('MASI')
# Load multiple assets
banks = cas.loadmany(['BCP', 'CIH', 'Attijariwafa'], start='2024-01-01', end='2024-12-31')
# Get intraday data
intraday = cas.get_intraday('BCP')
API Reference
Historical Data
get_history(identifier, start=None, end=None)
Get historical daily data for a stock or index.
# Stock data
df = cas.get_history('Addoha', start='2024-01-01', end='2024-06-30')
# Index data
masi = cas.get_history('MASI')
msi20 = cas.get_history('MSI20')
Returns: DataFrame with columns: Value, Min, Max, Variation, Volume
loadmany(*assets, start=None, end=None, feature='Value')
Load data for multiple assets.
# Load closing prices
df = cas.loadmany(['BCP', 'CIH', 'BOA'], start='2024-01-01', end='2024-12-31')
# Load volumes
volumes = cas.loadmany(['BCP', 'CIH'], feature='Volume')
Intraday Data
get_intraday(identifier)
Get intraday prices for a stock or index.
# Stock intraday
intraday = cas.get_intraday('BCP')
# Market intraday
market = cas.get_intraday('MASI')
Company Information
⚠️ Temporarily Unavailable: The following functions are currently deprecated due to changes in the casablanca-bourse.com website structure. They return empty dictionaries with deprecation warnings. See ROADMAP.md for restoration timeline.
getCours(name) (deprecated)
Get session data, latest transactions, and order book.
cours = cas.getCours('BOA') # Returns {} with deprecation warning
getKeyIndicators(name) (deprecated)
Get company key indicators and financial ratios.
indicators = cas.getKeyIndicators('Attijariwafa') # Returns {} with deprecation warning
getDividend(name) (deprecated)
Get dividend history.
dividends = cas.getDividend('BOA') # Returns {} with deprecation warning
Market Overview
getIndex() (deprecated)
Get all index summaries.
index = cas.getIndex() # Returns {} with deprecation warning
getPond()
Get index weights (pondération).
weights = cas.getPond()
getIndexRecap() (deprecated)
Get session recap with top gainers/losers.
recap = cas.getIndexRecap() # Returns {} with deprecation warning
Utilities
notation()
Get list of all available asset names.
assets = cas.notation()
get_isin_by_name(name)
Get ISIN code for an asset. Supports aliases like CFG, CMG, IAM, MDP, SAM.
isin = cas.get_isin_by_name('BCP') # Returns 'MA0000011884'
isin = cas.get_isin_by_name('IAM') # Returns 'MA0000011488' (alias for Maroc Telecom)
Data Sources
- Historical & Intraday Data: Medias24 API
- Company Info & Market Data: Bourse de Casablanca
Requirements
- Python 3.7+
- requests
- beautifulsoup4
- pandas
- lxml
Example Notebook
See casased_exemple.ipynb for a complete demonstration of all features.
Release Notes
- v0.2.0 — 2026-01-14 — Added asset aliases (CFG, CMG, IAM, MDP, SAM), deprecated broken scraping functions, updated HPS ISIN, added ROADMAP.md
- v0.1.2 — 2026-01-06 — Documentation cleanup, branding updates
- v0.1.1 — 2026-01-06 — Remove demo videos, update branding
- v0.1.0 — Initial release
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT License — see LICENSE for details.
Contact
- GitHub: QuantBender/casased
- Twitter: @AmineAndam
- LinkedIn: ANDAM AMINE
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file casased-0.2.0.tar.gz.
File metadata
- Download URL: casased-0.2.0.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2e10e8acf5de6fb9c355ccca5821a4bce80ff44e9e92d2847a20a04211f5def
|
|
| MD5 |
6c442ac190a905273675bf19b01d17e2
|
|
| BLAKE2b-256 |
4ed554917f4b442c0fcf71daa91808ea524ff18ee4893e39e1d5f86d5eaad14f
|
File details
Details for the file casased-0.2.0-py3-none-any.whl.
File metadata
- Download URL: casased-0.2.0-py3-none-any.whl
- Upload date:
- Size: 17.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43fe6689ddf77426048b2f06dda4bd0a393157a66c2340d07d85c381934ad166
|
|
| MD5 |
260f5ac543527404275b94ee2c2f1aa7
|
|
| BLAKE2b-256 |
7aff300b3a153af10095fe82ed7855be0321fbcbdffa440cbb52b3fd606d14d0
|