cbe package
Submodules
cbe.open_data module
- class cbe.open_data.CBEOpenData(zip_path: str, db_path: str = ':memory:', force_load: bool = False, schema_path: str = None)[source]
Bases:
objectA class to interact with CBE (Crossroads Bank for Enterprises) Open Data files.
This class provides methods to load, query, and analyze CBE Open Data, which contains information about enterprises, establishments, and their associated data (e.g., addresses, activities, contacts, etc.). The data is typically provided in a ZIP file containing CSV files, which are loaded into an SQLite database for efficient querying.
The class supports: - Loading data from a local ZIP file. - Querying enterprise details, denominations, addresses, activities, contacts, and more. - Replacing code-based fields with their human-readable descriptions using CBE code tables. - Mimicking the data structure available on the CBE Public Search website.
Links: - CBE Open Data Portal: https://kbopub.economie.fgov.be/kbo-open-data/ - CBE Public Search: https://kbopub.economie.fgov.be/kbopub/zoeknummerform.html - CBE Extra Info: https://economie.fgov.be/nl/themas/ondernemingen/kruispuntbank-van/diensten-voor-iedereen/hergebruik-van-publieke
- zip_path
Path to the ZIP file containing CBE Open Data.
- Type:
str
- db_path
Path to the SQLite database (defaults to in-memory database).
- Type:
str
- schema_path
Path to the SQL schema file for creating database tables.
- Type:
str
- force_load
Whether to force reloading of data even if it already exists in the database.
- Type:
bool
- db_conn
Connection to the SQLite database.
- Type:
sqlite3.Connection
- zip_file
Handle to the opened ZIP file.
- Type:
zipfile.ZipFile
- get_enterprise()[source]
Retrieves enterprise details with code-based fields replaced by descriptions.
- search()[source]
Retrieves all information tied to an enterprise number, mimicking the CBE Public Search website.
Example
>>> cbe_open_data = CBEOpenData( zip_path='KboOpenData_0133_2025_03_Full.zip', db_path='cbe_open_data.db', force_load=True ) >>> enterprise_info = cbe_open_data.search("1234.567.890") >>> print(enterprise_info)
Notes
The class uses an LRU cache to optimize repeated queries.
Ensure the schema file is correctly configured to match the CSV file structure.
- REQUIRED_FILES = {'activity.csv', 'address.csv', 'branch.csv', 'code.csv', 'contact.csv', 'denomination.csv', 'enterprise.csv', 'establishment.csv', 'meta.csv'}
- get_activities(entity_number: str, language: str = 'NL') list[source]
Retrieve activities for a given entity (enterprise or establishment).
- Parameters:
entity_number (str) – The entity number (enterprise or establishment number).
language (str) – The language for code table descriptions.
- Returns:
A list of activities with code table lookups applied.
- Return type:
list
- get_addresses(entity_number: str, language: str = 'NL') list[source]
Retrieve addresses for a given entity (enterprise or establishment).
- Parameters:
entity_number (str) – The entity number (enterprise or establishment number).
language (str) – The language for code table descriptions.
- Returns:
A list of addresses with code table lookups applied.
- Return type:
list
- get_branches(enterprise_number: str) list[source]
Retrieve branches for a given enterprise.
- Parameters:
enterprise_number (str) – The enterprise number in the format ‘XXXX.XXX.XXX’.
- Returns:
A list of branches.
- Return type:
list
- get_code(category: str, code: str, language: str = 'NL') dict[source]
Fetch the code table entry for a given category, code, and language.
- Parameters:
category (str) – The category of the code (e.g., “Status”, “JuridicalSituation”).
code (str) – The code to look up.
language (str) – The language of the description (default is “NL” for Dutch).
- Returns:
A dictionary containing the code, language, and description.
- Return type:
dict
- get_contacts(entity_number: str, language: str = 'NL') list[source]
Retrieve contacts for a given entity (enterprise or establishment).
- Parameters:
entity_number (str) – The entity number (enterprise or establishment number).
language (str) – The language for code table descriptions.
- Returns:
A list of contacts with code table lookups applied.
- Return type:
list
- get_denominations(entity_number: str, language: str = 'NL') list[source]
Retrieve denominations for a given entity (enterprise or establishment).
- Parameters:
entity_number (str) – The entity number (enterprise or establishment number).
language (str) – The language for code table descriptions.
- Returns:
A list of denominations with code table lookups applied.
- Return type:
list
- get_enterprise(enterprise_number: str, language: str = 'NL') dict[source]
Retrieve enterprise details and replace code-based fields with their descriptions.
- Parameters:
enterprise_number (str) – The enterprise number in the format ‘XXXX.XXX.XXX’.
language (str) – The language for code table descriptions.
- Returns:
A dictionary containing enterprise details with code table lookups applied.
- Return type:
dict
- get_establishments(enterprise_number: str, language: str = 'NL') list[source]
Retrieve establishments for a given enterprise, including their addresses and denominations.
- Parameters:
enterprise_number (str) – The enterprise number in the format ‘XXXX.XXX.XXX’.
language (str) – The language for code table descriptions.
- Returns:
A list of establishments with their addresses and denominations.
- Return type:
list
- search(enterprise_number: str, language: str = 'NL') dict[source]
Retrieve all information tied to an enterprise number, including enterprise details, denominations, addresses, establishments, contacts, activities, and branches. This function mimics the data structure and details available on the CBE Public Search website (https://kbopub.economie.fgov.be/kbopub/zoeknummerform.html).
The function replaces code-based fields (e.g., Status, JuridicalSituation, TypeOfEnterprise) with their corresponding descriptions from the CBE code tables, based on the specified language.
- Parameters:
enterprise_number (str) – The enterprise number in the format ‘XXXX.XXX.XXX’.
language (str) – The language for code table descriptions (e.g., “NL”, “FR”, “DE”, “EN”).
- Returns:
A dictionary containing all information tied to the enterprise, with code table lookups applied.
- Return type:
dict
cbe.portal module
- class cbe.portal.CBEOpenDataPortal(username: str, password: str)[source]
Bases:
objectA class to interact with the CBE (Crossroads Bank for Enterprises) Open Data portal.
This class provides methods to authenticate with the CBE Open Data portal, retrieve available data extracts, and download specific or the latest extract files. The data extracts are typically provided as ZIP files containing CSV files, which can be used for further processing and analysis.
- BASE_URL
The base URL for the CBE Open Data portal.
- Type:
str
- LOGIN_ENDPOINT
The endpoint for authenticating with the CBE Open Data portal.
- Type:
str
- EXTRACT_PAGE
The URL of the page listing available extract files.
- Type:
str
- EXTRACT_FILE_NAME
A regex pattern to parse extract file names and extract metadata.
- Type:
str
- __init__()[source]
Initializes the CBEOpenDataPortal instance and logs in to the CBE Open Data portal.
- list_available_extracts()[source]
Retrieves a list of available extract files from the CBE Open Data portal.
Example
>>> portal = CBEOpenDataPortal(username="your_username", password="your_password") >>> extracts = portal.list_available_extracts() >>> for extract in extracts: ... print(f"Extract: {extract}") >>> extract_url = portal.get_extract_url(extract_number="0133") >>> print(f"Extract Url: {extract_url}") >>> portal.download_zip(extract_number="0133")
Notes
The CBE Open Data portal requires authentication to access extract files.
The class uses the requests library for HTTP requests and BeautifulSoup for parsing HTML.
Extracts are identified by their extract number, year, month, and type (e.g., “Full” or “Update”).
- BASE_EXTRACT_URL = 'https://kbopub.economie.fgov.be/kbo-open-data/affiliation/xml'
- BASE_URL = 'https://kbopub.economie.fgov.be/kbo-open-data'
- EXTRACT_FILE_NAME = '.*(?P<extract_number>\\d{4})_(?P<year>\\d{4})_(?P<month_num>\\d{2})_.*(?P<extract_type>Full|Update).zip'
- EXTRACT_PAGE = 'https://kbopub.economie.fgov.be/kbo-open-data/affiliation/xml/?files'
- LOGIN_ENDPOINT = 'https://kbopub.economie.fgov.be/kbo-open-data/static/j_spring_security_check'
- download_zip(extract_number: str = None, extract_type: str = 'Full', download_dir: str = 'data', force_download: bool = False) str[source]
Downloads the CBE Open Data ZIP file from the official CBE portal.
This method downloads the ZIP file for the specified extract (or the latest one). The downloaded file is saved in download_dir with its original name (e.g., KboOpenData_0133_2025_03_Full.zip).
- Parameters:
extract_number (str, optional) – The extract number to download. Defaults to latest.
extract_type (str, optional) – The extract type, either ‘Full’ or ‘Update’. Defaults to ‘Full’.
download_dir (str, optional) – Directory to save the downloaded ZIP file. Defaults to “data”.
force_download (bool, optional) – Whether to overwrite an existing file. Defaults to False.
- Returns:
The path of the downloaded ZIP file.
- Return type:
str
- Raises:
ValueError – If the download process encounters an error or if extract is not found.
- get_extract_url(extract_number: str = None, extract_type: str = 'Full') str[source]
Retrieves the file path of the CBE extract file based on the provided extract number.
If an extract number is provided, it will return the corresponding file path, if not provided, it will return the latest extract found.
- Parameters:
extract_number (str, optional) – The extract number to find a specific extract file. If not provided, the most recent extract will be returned.
extract_type (str, optional) – The extract type, either ‘Full’ or ‘Update’. Defaults to ‘Full’.
- Returns:
The file path of the requested CBE extract file.
- Return type:
str
- Raises:
ValueError – If an extract with the specified number is not found or no extracts are found at all.
- list_available_extracts() list[source]
Retrieves available extract files from the CBE Open Data page.
- Returns:
A list of dictionaries representing the available extract files.
Each dictionary has the following keys: - extract_number: The extract number (e.g., “0133”). - year: The year of the extract (e.g., “2024”). - month_num: The month of the extract (e.g., “03”). - extract_type: The type of the extract (e.g., “Full” or “Update”). - file_url: The file url of the extract.
- Return type:
list
- Raises:
ValueError – If no extracts are found at all.
- static login_to_cbe(username: str, password: str) Session[source]
Logs into the CBE Open Data portal and returns an authenticated session.
- Parameters:
username (str) – The username for logging in.
password (str) – The password for logging in.
- Returns:
An authenticated session object for subsequent requests.
- Return type:
requests.Session
- Raises:
ValueError – If authentication fails.
Module contents
- class cbe.CBEOpenData(zip_path: str, db_path: str = ':memory:', force_load: bool = False, schema_path: str = None)[source]
Bases:
objectA class to interact with CBE (Crossroads Bank for Enterprises) Open Data files.
This class provides methods to load, query, and analyze CBE Open Data, which contains information about enterprises, establishments, and their associated data (e.g., addresses, activities, contacts, etc.). The data is typically provided in a ZIP file containing CSV files, which are loaded into an SQLite database for efficient querying.
The class supports: - Loading data from a local ZIP file. - Querying enterprise details, denominations, addresses, activities, contacts, and more. - Replacing code-based fields with their human-readable descriptions using CBE code tables. - Mimicking the data structure available on the CBE Public Search website.
Links: - CBE Open Data Portal: https://kbopub.economie.fgov.be/kbo-open-data/ - CBE Public Search: https://kbopub.economie.fgov.be/kbopub/zoeknummerform.html - CBE Extra Info: https://economie.fgov.be/nl/themas/ondernemingen/kruispuntbank-van/diensten-voor-iedereen/hergebruik-van-publieke
- zip_path
Path to the ZIP file containing CBE Open Data.
- Type:
str
- db_path
Path to the SQLite database (defaults to in-memory database).
- Type:
str
- schema_path
Path to the SQL schema file for creating database tables.
- Type:
str
- force_load
Whether to force reloading of data even if it already exists in the database.
- Type:
bool
- db_conn
Connection to the SQLite database.
- Type:
sqlite3.Connection
- zip_file
Handle to the opened ZIP file.
- Type:
zipfile.ZipFile
- get_enterprise()[source]
Retrieves enterprise details with code-based fields replaced by descriptions.
- search()[source]
Retrieves all information tied to an enterprise number, mimicking the CBE Public Search website.
Example
>>> cbe_open_data = CBEOpenData( zip_path='KboOpenData_0133_2025_03_Full.zip', db_path='cbe_open_data.db', force_load=True ) >>> enterprise_info = cbe_open_data.search("1234.567.890") >>> print(enterprise_info)
Notes
The class uses an LRU cache to optimize repeated queries.
Ensure the schema file is correctly configured to match the CSV file structure.
- REQUIRED_FILES = {'activity.csv', 'address.csv', 'branch.csv', 'code.csv', 'contact.csv', 'denomination.csv', 'enterprise.csv', 'establishment.csv', 'meta.csv'}
- get_activities(entity_number: str, language: str = 'NL') list[source]
Retrieve activities for a given entity (enterprise or establishment).
- Parameters:
entity_number (str) – The entity number (enterprise or establishment number).
language (str) – The language for code table descriptions.
- Returns:
A list of activities with code table lookups applied.
- Return type:
list
- get_addresses(entity_number: str, language: str = 'NL') list[source]
Retrieve addresses for a given entity (enterprise or establishment).
- Parameters:
entity_number (str) – The entity number (enterprise or establishment number).
language (str) – The language for code table descriptions.
- Returns:
A list of addresses with code table lookups applied.
- Return type:
list
- get_branches(enterprise_number: str) list[source]
Retrieve branches for a given enterprise.
- Parameters:
enterprise_number (str) – The enterprise number in the format ‘XXXX.XXX.XXX’.
- Returns:
A list of branches.
- Return type:
list
- get_code(category: str, code: str, language: str = 'NL') dict[source]
Fetch the code table entry for a given category, code, and language.
- Parameters:
category (str) – The category of the code (e.g., “Status”, “JuridicalSituation”).
code (str) – The code to look up.
language (str) – The language of the description (default is “NL” for Dutch).
- Returns:
A dictionary containing the code, language, and description.
- Return type:
dict
- get_contacts(entity_number: str, language: str = 'NL') list[source]
Retrieve contacts for a given entity (enterprise or establishment).
- Parameters:
entity_number (str) – The entity number (enterprise or establishment number).
language (str) – The language for code table descriptions.
- Returns:
A list of contacts with code table lookups applied.
- Return type:
list
- get_denominations(entity_number: str, language: str = 'NL') list[source]
Retrieve denominations for a given entity (enterprise or establishment).
- Parameters:
entity_number (str) – The entity number (enterprise or establishment number).
language (str) – The language for code table descriptions.
- Returns:
A list of denominations with code table lookups applied.
- Return type:
list
- get_enterprise(enterprise_number: str, language: str = 'NL') dict[source]
Retrieve enterprise details and replace code-based fields with their descriptions.
- Parameters:
enterprise_number (str) – The enterprise number in the format ‘XXXX.XXX.XXX’.
language (str) – The language for code table descriptions.
- Returns:
A dictionary containing enterprise details with code table lookups applied.
- Return type:
dict
- get_establishments(enterprise_number: str, language: str = 'NL') list[source]
Retrieve establishments for a given enterprise, including their addresses and denominations.
- Parameters:
enterprise_number (str) – The enterprise number in the format ‘XXXX.XXX.XXX’.
language (str) – The language for code table descriptions.
- Returns:
A list of establishments with their addresses and denominations.
- Return type:
list
- search(enterprise_number: str, language: str = 'NL') dict[source]
Retrieve all information tied to an enterprise number, including enterprise details, denominations, addresses, establishments, contacts, activities, and branches. This function mimics the data structure and details available on the CBE Public Search website (https://kbopub.economie.fgov.be/kbopub/zoeknummerform.html).
The function replaces code-based fields (e.g., Status, JuridicalSituation, TypeOfEnterprise) with their corresponding descriptions from the CBE code tables, based on the specified language.
- Parameters:
enterprise_number (str) – The enterprise number in the format ‘XXXX.XXX.XXX’.
language (str) – The language for code table descriptions (e.g., “NL”, “FR”, “DE”, “EN”).
- Returns:
A dictionary containing all information tied to the enterprise, with code table lookups applied.
- Return type:
dict
- class cbe.CBEOpenDataPortal(username: str, password: str)[source]
Bases:
objectA class to interact with the CBE (Crossroads Bank for Enterprises) Open Data portal.
This class provides methods to authenticate with the CBE Open Data portal, retrieve available data extracts, and download specific or the latest extract files. The data extracts are typically provided as ZIP files containing CSV files, which can be used for further processing and analysis.
- BASE_URL
The base URL for the CBE Open Data portal.
- Type:
str
- LOGIN_ENDPOINT
The endpoint for authenticating with the CBE Open Data portal.
- Type:
str
- EXTRACT_PAGE
The URL of the page listing available extract files.
- Type:
str
- EXTRACT_FILE_NAME
A regex pattern to parse extract file names and extract metadata.
- Type:
str
- __init__()[source]
Initializes the CBEOpenDataPortal instance and logs in to the CBE Open Data portal.
- list_available_extracts()[source]
Retrieves a list of available extract files from the CBE Open Data portal.
Example
>>> portal = CBEOpenDataPortal(username="your_username", password="your_password") >>> extracts = portal.list_available_extracts() >>> for extract in extracts: ... print(f"Extract: {extract}") >>> extract_url = portal.get_extract_url(extract_number="0133") >>> print(f"Extract Url: {extract_url}") >>> portal.download_zip(extract_number="0133")
Notes
The CBE Open Data portal requires authentication to access extract files.
The class uses the requests library for HTTP requests and BeautifulSoup for parsing HTML.
Extracts are identified by their extract number, year, month, and type (e.g., “Full” or “Update”).
- BASE_EXTRACT_URL = 'https://kbopub.economie.fgov.be/kbo-open-data/affiliation/xml'
- BASE_URL = 'https://kbopub.economie.fgov.be/kbo-open-data'
- EXTRACT_FILE_NAME = '.*(?P<extract_number>\\d{4})_(?P<year>\\d{4})_(?P<month_num>\\d{2})_.*(?P<extract_type>Full|Update).zip'
- EXTRACT_PAGE = 'https://kbopub.economie.fgov.be/kbo-open-data/affiliation/xml/?files'
- LOGIN_ENDPOINT = 'https://kbopub.economie.fgov.be/kbo-open-data/static/j_spring_security_check'
- download_zip(extract_number: str = None, extract_type: str = 'Full', download_dir: str = 'data', force_download: bool = False) str[source]
Downloads the CBE Open Data ZIP file from the official CBE portal.
This method downloads the ZIP file for the specified extract (or the latest one). The downloaded file is saved in download_dir with its original name (e.g., KboOpenData_0133_2025_03_Full.zip).
- Parameters:
extract_number (str, optional) – The extract number to download. Defaults to latest.
extract_type (str, optional) – The extract type, either ‘Full’ or ‘Update’. Defaults to ‘Full’.
download_dir (str, optional) – Directory to save the downloaded ZIP file. Defaults to “data”.
force_download (bool, optional) – Whether to overwrite an existing file. Defaults to False.
- Returns:
The path of the downloaded ZIP file.
- Return type:
str
- Raises:
ValueError – If the download process encounters an error or if extract is not found.
- get_extract_url(extract_number: str = None, extract_type: str = 'Full') str[source]
Retrieves the file path of the CBE extract file based on the provided extract number.
If an extract number is provided, it will return the corresponding file path, if not provided, it will return the latest extract found.
- Parameters:
extract_number (str, optional) – The extract number to find a specific extract file. If not provided, the most recent extract will be returned.
extract_type (str, optional) – The extract type, either ‘Full’ or ‘Update’. Defaults to ‘Full’.
- Returns:
The file path of the requested CBE extract file.
- Return type:
str
- Raises:
ValueError – If an extract with the specified number is not found or no extracts are found at all.
- list_available_extracts() list[source]
Retrieves available extract files from the CBE Open Data page.
- Returns:
A list of dictionaries representing the available extract files.
Each dictionary has the following keys: - extract_number: The extract number (e.g., “0133”). - year: The year of the extract (e.g., “2024”). - month_num: The month of the extract (e.g., “03”). - extract_type: The type of the extract (e.g., “Full” or “Update”). - file_url: The file url of the extract.
- Return type:
list
- Raises:
ValueError – If no extracts are found at all.
- static login_to_cbe(username: str, password: str) Session[source]
Logs into the CBE Open Data portal and returns an authenticated session.
- Parameters:
username (str) – The username for logging in.
password (str) – The password for logging in.
- Returns:
An authenticated session object for subsequent requests.
- Return type:
requests.Session
- Raises:
ValueError – If authentication fails.