Skip to main content

Core datatypes for stele1 climbing catalogs

Project description

stele1-datatypes

Core datatypes for stele1 catalogs.

Covers Metadata, Climb, Area, Photo, Parking, and Trail. See the stele1 spec for the data model these implement.

Each datatype validates its input and exposes from_data / to_data for serialization to and from plain dicts.

Use

from uuid import uuid4
from stele1.climb import Climb

# from existing data
climb = Climb.from_data({
    'uuid': '550e8400-e29b-41d4-a716-446655440000',
    'name': 'Centerpede',
    'rating': {'difficulty': 'V4'},
})

# or built up directly
other = Climb(uuid4())
other.name = 'Millipede'
other.rating = {'difficulty': 'V5'}

climb.name                       # 'Centerpede'
climb.name = 'Centerpede Low'
climb.rating = None              # remove an attribute

climb.to_data()                  # plain dict, ready for json.dumps

Attributes are plain values: strings, numbers, tuples, dicts. Assigning validates immediately; invalid values raise TypeError or ValueError at the assignment, naming the problem:

climb.length = {'lower_estimate': 3, 'upper_estimate': 2, 'unit': 'meters'}
# ValueError: climb .length lower_estimate must not exceed upper_estimate

Every record requires a uuid at construction. uuid.UUID instances are accepted and stored as the canonical lowercase string.

to_data returns fresh plain dicts. json.dumps(climb.to_data()) produces spec-compliant output; formatting is up to the caller. Sequence attributes are returned as tuples; to change one, assign a new value:

climb.tags = [*(climb.tags or ()), 'highball']

Attribute validators

Each datatype module also exposes its attribute validators, usable on their own:

from stele1.climb import validate_rating

validate_rating({'difficulty': 'V12'})   # returns the validated value
validate_rating({})                      # raises ValueError

Compatibility behavior

Per the spec's versioning rules: unknown top-level attributes are preserved verbatim through from_data / to_data, and unknown nested keys raise.

Some checks here are deliberately stricter than the spec; they are marked beyond spec in the source. To read records that this strictness rejects, use DictCatalog from stele1-filesystem.

Install

pip install stele1-datatypes

Development

Source and issues live at codeberg.org/stele-climbing/stele1.

License

MIT

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

stele1_datatypes-0.3.8.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stele1_datatypes-0.3.8-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file stele1_datatypes-0.3.8.tar.gz.

File metadata

  • Download URL: stele1_datatypes-0.3.8.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for stele1_datatypes-0.3.8.tar.gz
Algorithm Hash digest
SHA256 58c134ca948f23122c884e9c27a38e746a23aac5cec83b20bb311b103ed3a155
MD5 4f17813ae86eccc2adc25eb7b6390db9
BLAKE2b-256 63307cc34023a6a7b2e7a2d2187faa6044a91b26bf6ed5c8dc856e6c54322340

See more details on using hashes here.

File details

Details for the file stele1_datatypes-0.3.8-py3-none-any.whl.

File metadata

File hashes

Hashes for stele1_datatypes-0.3.8-py3-none-any.whl
Algorithm Hash digest
SHA256 877abf6474852ee669fac95f8b701af92befabe721f821d99b38fc8ac74c9729
MD5 6ae84bf22794f64e0ec2d4cb33ad1257
BLAKE2b-256 f5144122905cea6fba4b47f0b8d9ad5686711db2fadccf86447854c124e39304

See more details on using hashes here.

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