trailpack.packing.datapackage_schema ==================================== .. py:module:: trailpack.packing.datapackage_schema .. autoapi-nested-parse:: DataPackage metadata schema and interactive builder classes using Pydantic. Provides structured definitions and UI-friendly methods for creating Frictionless Data Package metadata with automatic validation. Attributes ---------- .. autoapisummary:: trailpack.packing.datapackage_schema.COMMON_LICENSES trailpack.packing.datapackage_schema.FIELD_TEMPLATES Classes ------- .. autoapisummary:: trailpack.packing.datapackage_schema.Contributor trailpack.packing.datapackage_schema.ContributorRole trailpack.packing.datapackage_schema.DataPackageSchema trailpack.packing.datapackage_schema.Field trailpack.packing.datapackage_schema.FieldConstraints trailpack.packing.datapackage_schema.FieldType trailpack.packing.datapackage_schema.License trailpack.packing.datapackage_schema.MetaDataBuilder trailpack.packing.datapackage_schema.Resource trailpack.packing.datapackage_schema.Source trailpack.packing.datapackage_schema.Unit Module Contents --------------- .. py:class:: Contributor Bases: :py:obj:`pydantic.BaseModel` Contributor information with validation. .. py:method:: to_dict() -> Dict[str, Any] Convert to dictionary format, excluding None values. .. py:method:: validate_email(v) :classmethod: Basic email validation. .. py:method:: validate_role(v) :classmethod: Validate role is from accepted list. .. py:attribute:: email :type: Optional[str] .. py:attribute:: name :type: str .. py:attribute:: organization :type: Optional[str] .. py:attribute:: role :type: str .. py:class:: ContributorRole Bases: :py:obj:`enum.Enum` Standard contributor roles. .. py:attribute:: AUTHOR :value: 'author' .. py:attribute:: CONTRIBUTOR :value: 'contributor' .. py:attribute:: MAINTAINER :value: 'maintainer' .. py:attribute:: PUBLISHER :value: 'publisher' .. py:attribute:: WRANGLER :value: 'wrangler' .. py:class:: DataPackageSchema DataPackage metadata schema definition with UI-friendly methods. Provides structure and validation for Frictionless Data Package metadata. Initialize the schema definition. .. py:method:: _create_field_definitions() -> Dict[str, Dict[str, Any]] Create field definitions for UI generation. .. py:method:: get_all_fields() -> List[str] Get list of all possible field names. .. py:method:: get_field_definition(field_name: str) -> Dict[str, Any] Get UI field definition for a specific field. .. py:method:: get_recommended_fields() -> List[str] Get list of recommended field names. .. py:method:: get_required_fields() -> List[str] Get list of required field names. .. py:method:: validate_package_name(name: str) -> tuple[bool, str] Validate package name format. .. py:method:: validate_url(url: str) -> tuple[bool, str] Validate URL format. .. py:method:: validate_version(version: str) -> tuple[bool, str] Validate semantic version format. .. py:attribute:: OPTIONAL_FIELDS :value: ['profile', 'keywords', 'homepage', 'repository', 'image', 'id'] .. py:attribute:: RECOMMENDED_FIELDS :value: ['description', 'version'] .. py:attribute:: REQUIRED_FIELDS :value: ['name', 'title', 'resources', 'licenses', 'created', 'contributors', 'sources'] .. py:attribute:: field_definitions .. py:class:: Field Bases: :py:obj:`pydantic.BaseModel` Data field schema definition with validation. .. py:method:: to_dict() -> Dict[str, Any] Convert to dictionary format. .. py:method:: validate_field_type(v) :classmethod: Validate field type is from accepted list. .. py:method:: validate_numeric_has_unit() Validate that numeric fields have a unit. .. py:attribute:: constraints :type: Optional[FieldConstraints] .. py:attribute:: description :type: Optional[str] .. py:attribute:: name :type: str .. py:attribute:: rdf_type :type: Optional[str] .. py:attribute:: taxonomy_url :type: Optional[str] .. py:attribute:: type :type: str .. py:attribute:: unit :type: Optional[Unit] .. py:class:: FieldConstraints Bases: :py:obj:`pydantic.BaseModel` Field validation constraints with validation. .. py:method:: to_dict() -> Dict[str, Any] Convert to dictionary format, excluding None values. .. py:method:: validate_numeric_constraints(v, info) :classmethod: Validate numeric constraints. .. py:method:: validate_pattern(v) :classmethod: Validate regex pattern. .. py:attribute:: enum :type: Optional[List[str]] .. py:attribute:: maximum :type: Optional[Union[int, float]] .. py:attribute:: minimum :type: Optional[Union[int, float]] .. py:attribute:: pattern :type: Optional[str] .. py:attribute:: required :type: Optional[bool] .. py:attribute:: unique :type: Optional[bool] .. py:class:: FieldType Bases: :py:obj:`enum.Enum` Supported field types in data packages. .. py:attribute:: BOOLEAN :value: 'boolean' .. py:attribute:: DATE :value: 'date' .. py:attribute:: DATETIME :value: 'datetime' .. py:attribute:: DURATION :value: 'duration' .. py:attribute:: INTEGER :value: 'integer' .. py:attribute:: NUMBER :value: 'number' .. py:attribute:: STRING :value: 'string' .. py:attribute:: TIME :value: 'time' .. py:class:: License Bases: :py:obj:`pydantic.BaseModel` License information with automatic validation. .. py:method:: to_dict() -> Dict[str, Any] Convert to dictionary format, excluding None values. .. py:method:: validate_path_url(v) :classmethod: Validate URL format. .. py:attribute:: name :type: str .. py:attribute:: path :type: Optional[str] .. py:attribute:: title :type: Optional[str] .. py:class:: MetaDataBuilder Interactive builder for creating DataPackage metadata. Can be used with UI frameworks to collect user input. Initialize the builder. .. py:method:: add_contributor(name: str, role: str = 'author', email: Optional[str] = None, organization: Optional[str] = None) -> MetaDataBuilder Add contributor information. .. py:method:: add_license(name: Optional[str] = None, title: Optional[str] = None, path: Optional[str] = None) -> MetaDataBuilder Add license information. Defaults to CC-BY-4.0 if no name provided. License name should be a valid SPDX identifier. path should be a valid URL to SPDX license page. See https://spdx.org/licenses/ for common licenses. .. py:method:: add_resource(resource: Resource) -> MetaDataBuilder Add a data resource. .. py:method:: add_source(title: str, path: Optional[str] = None, description: Optional[str] = None) -> MetaDataBuilder Add data source information. .. py:method:: build() -> Dict[str, Any] Build the complete metadata dictionary. .. py:method:: get_current_state() -> Dict[str, Any] Get current builder state for UI display. .. py:method:: get_ui_fields() -> Dict[str, Dict[str, Any]] Get field definitions for UI generation. .. py:method:: set_basic_info(name: str, title: Optional[str] = None, description: Optional[str] = None, version: Optional[str] = None) -> MetaDataBuilder Set basic package information. .. py:method:: set_dates() -> MetaDataBuilder Set creation date to current time .. py:method:: set_keywords(keywords: List[str]) -> MetaDataBuilder Set keywords/tags. .. py:method:: set_links(homepage: Optional[str] = None, repository: Optional[str] = None) -> MetaDataBuilder Set homepage and repository URLs. .. py:method:: set_profile(profile: str) -> MetaDataBuilder Set package profile. .. py:attribute:: contributors :value: [] .. py:attribute:: licenses :value: [] .. py:attribute:: metadata .. py:attribute:: resources :value: [] .. py:attribute:: schema .. py:attribute:: sources :value: [] .. py:class:: Resource Bases: :py:obj:`pydantic.BaseModel` Data resource (file) definition with validation. .. py:method:: to_dict() -> Dict[str, Any] Convert to dictionary format. .. py:method:: validate_encoding(v) :classmethod: Validate encoding is valid. .. py:method:: validate_format(v) :classmethod: Validate format is recognized. .. py:attribute:: description :type: Optional[str] .. py:attribute:: encoding :type: str .. py:attribute:: fields :type: List[Field] .. py:attribute:: format :type: Optional[str] .. py:attribute:: mediatype :type: Optional[str] .. py:attribute:: name :type: str .. py:attribute:: path :type: str .. py:attribute:: primary_key :type: List[str] .. py:attribute:: profile :type: Optional[str] .. py:attribute:: title :type: Optional[str] .. py:class:: Source Bases: :py:obj:`pydantic.BaseModel` Data source information with validation. .. py:method:: to_dict() -> Dict[str, Any] Convert to dictionary format, excluding None values. .. py:method:: validate_path(v) :classmethod: Basic path validation. .. py:attribute:: description :type: Optional[str] .. py:attribute:: path :type: Optional[str] .. py:attribute:: title :type: str .. py:class:: Unit Bases: :py:obj:`pydantic.BaseModel` Unit of measurement with QUDT vocabulary support. .. py:method:: to_dict() -> Dict[str, Any] Convert to dictionary format for metadata. .. py:method:: validate_path_url(v) :classmethod: Validate URI format. .. py:attribute:: long_name :type: Optional[str] .. py:attribute:: name :type: str .. py:attribute:: path :type: Optional[str] .. py:data:: COMMON_LICENSES .. py:data:: FIELD_TEMPLATES