This page captures the shared infrastructure that keeps all regions inside $steelsnakes$ synchronized: the data caches (SectionDatabase) and the wiring layer (SectionFactory) that turns cached rows into concrete section objects.
SectionDatabase
- Discovery & caching. When you instantiate
SectionDatabase, it auto-discovers the correctdata/<REGION>/directory via several fallback paths, optionally respects an injecteddata_directory, and loads every supportedSectionTypeinto a dictionary cache. Metadata like_section_typeand_regionare added to every entry so downstream tools understand the source. - Fallback SQLite support. The constructor accepts
use_sqlite=True, in which case_load_section_typecan attempt to read from an SQLite table named after eachSectionTypewhen JSON files are absent. Error handling already logs missing tables and malformed rows without breaking the entire initialization. - Resilient lookup helpers.
find_sectionfirst tries an exact match, then_fuzzy_find_section: - Exact matches ignore case and normalize separators (
,-,_,×). - Difflib-based similarity matching provides a controlled suggestion (cutoff 0.8) before falling back to
None. get_similar_sectionscan be called independently withnsuggestions across all loaded types.- Criteria-based search.
search_sections(section_type, prop__gt=100, prop__eq="W")filters the cached dict via comparison operators (gt,lt,gte,lte,eq,ne) and exact matches, so you can quickly find all sections that meet size thresholds.
Note
The current database is JSON-first and still mirrors early datasets, so not every region/type has fully verified values. Validate against the source CSV/JSON, especially when drafting code that depends on exact masses or moments of inertia.
SectionFactory
SectionFactory bridges SectionDatabase with the concrete section classes.
- Automatic class loading. If no
section_classesmapping is provided, the factory inspectsdatabase.regionand imports the relevant modules (UK,EU,US,AU,NZare wired in), while gracefully logging if a region lacks exports. - Region-aware wiring. Each helper (e.g.,
_load_UK_classes) imports the region's section definitions (beams, channels, angles, hollow sections) and maps them toSectionTypemembers. This keeps the factory thin while letting each region evolve independently. - Extensibility. Custom section classes or alternative databases can simply pass their own
section_classesdict when instantiating the factory, so testing helpers can swap in fake sections without touching the auto-loader.
Pair any factory instance with the database you already created to request a section instance:
from steelsnakes.base.database import SectionDatabase
from steelsnakes.base.factory import SectionFactory
from steelsnakes.base.sections import SectionType
db = SectionDatabase(region="UK")
factory = SectionFactory(database=db)
beam = factory.create_section("457x191x67", section_type=SectionType.UB)
The next page in this reference dives into the region-specific APIs for UK, EU, US, and additional locales.