Skip to main content

Borme

The Borme class represents a parsed BORME (Boletín Oficial del Registro Mercantil) document containing commercial registry announcements.

Constructor

Borme(date, seccion, provincia, num, cve, anuncios=None, filename=None, lazy=True)
date
datetime.date | tuple
required
The publication date. Can be a datetime.date object or a tuple (year, month, day).
seccion
str
required
The BORME section (e.g., ‘A’ for acts, ‘C’ for announcements).
provincia
str | Provincia
required
The province name or Provincia object.
num
int
required
The BORME bulletin number.
cve
str
required
The CVE (verification code) identifier.
anuncios
list[BormeAnuncio]
default:"None"
List of announcements contained in the BORME.
filename
str
default:"None"
Path to the source PDF file if loaded from disk.
lazy
bool
default:"True"
If False, sets the URL immediately. Otherwise, URL is computed on demand.

Properties

date
datetime.date
The publication date of this BORME.
seccion
str
The BORME section identifier.
provincia
str | Provincia
The province for this BORME.
num
int
The bulletin number.
cve
str
The CVE verification code.
filename
str
Path to the source file if available.
url
str
Download URL for the BORME PDF. Computed lazily on first access.
anuncios
dict[int, BormeAnuncio]
Dictionary mapping announcement IDs to BormeAnuncio objects.
anuncios_rango
tuple[int, int]
Tuple with the minimum and maximum announcement IDs (from_anuncio, to_anuncio).

Methods

get_anuncio()

def get_anuncio(self, anuncio_id: int) -> BormeAnuncio
Retrieves a specific announcement by its ID.
anuncio_id
int
required
The announcement ID number.
return
BormeAnuncio
The announcement with the specified ID.
Raises: BormeAnuncioNotFound if the announcement ID doesn’t exist.

get_anuncios_ids()

def get_anuncios_ids(self) -> list[int]
Returns a sorted list of all announcement IDs.
return
list[int]
Sorted list of announcement IDs.

get_anuncios()

def get_anuncios(self) -> list[BormeAnuncio]
Returns all announcements as a list.
return
list[BormeAnuncio]
List of all BormeAnuncio objects.

download()

def download(self, filename: str) -> bool
Downloads the BORME PDF to the specified file path.
filename
str
required
Path where the PDF should be saved.
return
bool
True if download succeeded.
Raises: BormeAlreadyDownloadedException if the BORME is already associated with a file.

to_json()

def to_json(self, path=None, overwrite=True, pretty=True, include_url=True) -> str | bool
Exports the BORME to JSON format.
path
str
default:"None"
Output path. Can be a directory or file. If None, uses the filename with .json extension.
overwrite
bool
default:"True"
Whether to overwrite existing files.
pretty
bool
default:"True"
Whether to format JSON with indentation for readability.
include_url
bool
default:"True"
Whether to include the download URL. Requires internet connection.
return
str | bool
Path to the created JSON file, or False if file exists and overwrite=False.
When include_url=True, this method requires an internet connection to fetch the BORME URL.

from_json()

@classmethod
def from_json(cls, filename: str | io.IOBase) -> Borme
Creates a Borme instance from a BORME-JSON file.
filename
str | io.IOBase
required
Path to a JSON file or an open file object.
return
Borme
A new Borme instance populated from the JSON data.
If the JSON was created with an older version of bormeparser, a warning is logged.

Usage Examples

Basic usage

from bormeparser import parse
from bormeparser import SECCION

# Parse a BORME PDF
borme = parse('BORME-A-2015-102-29.pdf', SECCION.A)

# Access properties
print(f"Date: {borme.date}")
print(f"Province: {borme.provincia}")
print(f"CVE: {borme.cve}")
print(f"Number of announcements: {len(borme.anuncios)}")

# Get announcement IDs
ids = borme.get_anuncios_ids()
print(f"Announcement IDs: {ids[0]} to {ids[-1]}")

Working with announcements

# Get specific announcement
anuncio = borme.get_anuncio(12345)
print(f"Company: {anuncio.empresa}")

# Iterate over all announcements
for anuncio in borme.get_anuncios():
    print(f"{anuncio.id}: {anuncio.empresa}")
    for acto_name, acto_value in anuncio.get_actos():
        print(f"  {acto_name}: {acto_value}")

Export to JSON

# Export with all options
json_path = borme.to_json(
    path="/tmp/borme_output",
    overwrite=True,
    pretty=True,
    include_url=True
)
print(f"Saved to: {json_path}")

# Load from JSON
borme_loaded = Borme.from_json(json_path)

BormeXML

The BormeXML class handles the daily BORME summary XML files that list all available BORME PDFs.

Constructor

BormeXML()
Creates an empty BormeXML instance. Use the static factory methods from_file() or from_date() to load data.

Properties

date
datetime.date
The publication date of this BORME XML.
nbo
int
Número de Boletín Oficial (official bulletin number).
filename
str
Path to the XML file if loaded from disk.
url
str
URL of the BORME XML file.
prev_borme
datetime.date
Date of the previous BORME publication.
next_borme
datetime.date | None
Date of the next BORME publication, or None if this is not final.
is_final
bool
Whether this is the final (definitive) version of the XML.

Factory Methods

from_file()

@staticmethod
def from_file(path: str, secure=True) -> BormeXML
Loads a BORME XML from a local file or URL.
path
str
required
File path or HTTP(S) URL to the XML file.
secure
bool
default:"True"
Whether to use HTTPS for URLs.
return
BormeXML
Loaded BormeXML instance.
Raises: IOError if file doesn’t exist, BormeDoesntExistException if not a valid BORME XML.

from_date()

@staticmethod
def from_date(date: datetime.date | tuple, secure=True) -> BormeXML
Fetches the BORME XML for a specific date from the official source.
date
datetime.date | tuple
required
Date as a datetime.date object or tuple (year, month, day).
secure
bool
default:"True"
Whether to use HTTPS.
return
BormeXML
Loaded BormeXML instance for the specified date.

Methods

get_url_pdfs()

def get_url_pdfs(self, seccion=None, provincia=None) -> dict[str, str]
Retrieves download URLs for BORME PDFs.
seccion
str
Filter by section (e.g., ‘A’, ‘B’, ‘C’). For section C, provincia is ignored.
provincia
str
Filter by province name.
return
dict
Dictionary mapping CVE/province to PDF URLs. Structure depends on parameters:
  • Both specified: {cve: url}
  • Only seccion: {provincia: url}
  • Only provincia: {seccion: url}
You must specify at least one of seccion or provincia.

get_cves()

def get_cves(self, seccion=None, provincia=None) -> list[str] | str
Retrieves CVE identifiers for BORME documents.
seccion
str
Filter by section.
provincia
str
Filter by province.
return
list[str] | str
List of CVE codes, or single CVE string if only one result.

get_sizes()

def get_sizes(self, seccion=None, provincia=None) -> dict[str, int]
Retrieves file sizes for BORME PDFs.
seccion
str
Filter by section.
provincia
str
Filter by province.
return
dict[str, int]
Dictionary mapping CVE to file size in bytes.

get_url_cve()

def get_url_cve(self, cve: str) -> str
Gets the download URL for a specific CVE.
cve
str
required
The CVE identifier.
return
str
Download URL for the BORME PDF.
Raises: AttributeError if CVE is not found.

get_provincias()

def get_provincias(self, seccion: str) -> list[str]
Lists all provinces with BORMEs in a specific section.
seccion
str
required
The section identifier.
return
list[str]
List of province names.

download_borme()

def download_borme(self, path: str, provincia=None, seccion=None) -> tuple[bool, list]
Downloads BORME PDFs to the specified directory.
path
str
required
Directory where files should be saved.
provincia
str
Province to download.
seccion
str
Section to download.
return
tuple[bool, list]
Tuple of (success, list_of_downloaded_files).

save_to_file()

def save_to_file(self, path: str) -> bool
Saves the XML to disk.
path
str
required
Output file path. Parent directories are created if needed.
return
bool
True on success.

Usage Examples

Load from date

from bormeparser.borme import BormeXML
import datetime

# Fetch BORME XML for a specific date
date = datetime.date(2015, 6, 2)
borme_xml = BormeXML.from_date(date)

print(f"Date: {borme_xml.date}")
print(f"Bulletin number: {borme_xml.nbo}")
print(f"Is final: {borme_xml.is_final}")

Get available PDFs

from bormeparser import SECCION, PROVINCIA

# Get all PDFs for section A
urls = borme_xml.get_url_pdfs(seccion=SECCION.A)
for provincia, url in urls.items():
    print(f"{provincia}: {url}")

# Get PDF for specific province and section
urls = borme_xml.get_url_pdfs(seccion=SECCION.A, provincia=PROVINCIA.MALAGA)
# Returns: {'BORME-A-2015-102-29': 'http://...'}

# Get CVEs and sizes
cves = borme_xml.get_cves(seccion=SECCION.A)
sizes = borme_xml.get_sizes(seccion=SECCION.A)

for cve in cves:
    print(f"{cve}: {sizes[cve]} bytes")

Download BORMEs

# Download all BORMEs for a province
success, files = borme_xml.download_borme(
    path="/tmp/borme",
    provincia="MÁLAGA",
    seccion=SECCION.A
)

print(f"Downloaded {len(files)} files")

# Save the XML itself
borme_xml.save_to_file("/tmp/borme/summary.xml")

Load from local file

# Load from local file
borme_xml = BormeXML.from_file("/path/to/BORME-S-20150602.xml")

# Or from URL
borme_xml = BormeXML.from_file(
    "http://www.boe.es/diario_borme/xml.php?id=BORME-S-20150602"
)

Build docs developers (and LLMs) love