Resource¶
The Data Resource model allows to manipulate a Pydantic model in Python according to the Data Resource specification
Usage¶
from dplib.models import Resource, Schema, Field
resource = Resource()
resource.name = 'name'
resource.path = 'table.csv'
resource.schema = Schema(fields=[Field(name='id', type='integer')])
print(resource.to_text(format="json"))
{
  "name": "name",
  "path": "table.csv",
  "schema": {
    "fields": [
      {
        "name": "id",
        "type": "integer"
      }
    ]
  }
}
Reference¶
            dplib.models.Resource
¶
    
              Bases: Model
Data Resource model
Source code in dplib/models/resource/resource.py
                19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206  |  | 
            basepath: Optional[str] = pydantic.Field(default=None, exclude=True)
  
      class-attribute
      instance-attribute
  
¶
    Basepath of the resource. The data path and dialect/schema will be relative to this basepath.
            bytes: Optional[int] = None
  
      class-attribute
      instance-attribute
  
¶
    Size of the file in bytes.
            contributors: List[Contributor] = []
  
      class-attribute
      instance-attribute
  
¶
    The people or organizations who contributed to this Data Package.
            data: Optional[Any] = None
  
      class-attribute
      instance-attribute
  
¶
    Resource data rather than being stored in external files can be shipped inline on a Resource using the data property.
            description: Optional[str] = None
  
      class-attribute
      instance-attribute
  
¶
    Description of the resource.
            dialect: Optional[Union[Dialect, str]] = None
  
      class-attribute
      instance-attribute
  
¶
    A dialect property MAY be provided to specify Table Dialect
            encoding: Optional[str] = None
  
      class-attribute
      instance-attribute
  
¶
    Specify the character encoding of the resource’s data file.
            format: Optional[str] = None
  
      class-attribute
      instance-attribute
  
¶
    Format e.g. ‘csv’, ‘xls’, ‘json’ etc. Would be expected to be the standard file extension for this type of resource.
            hash: Optional[str] = None
  
      class-attribute
      instance-attribute
  
¶
    The MD5 hash for this resource. Other algorithms can be indicated by prefixing the hash’s value with the algorithm name in lower-case.
            licenses: List[License] = []
  
      class-attribute
      instance-attribute
  
¶
    The license(s) under which the resource is provided. This property is not legally binding and does not guarantee the package is licensed under the terms defined in this property.
            mediatype: Optional[str] = None
  
      class-attribute
      instance-attribute
  
¶
    The mediatype/mimetype of the resource e.g. “text/csv”, or “application/vnd.ms-excel”.
            name: Optional[str] = None
  
      class-attribute
      instance-attribute
  
¶
    A resource MUST contain a name property. The name is a simple name or identifier to be used for this resource.
            path: Optional[Union[str, List[str]]] = None
  
      class-attribute
      instance-attribute
  
¶
    Path to the data file or to a list of data files
            profile: str = pydantic.Field(default=settings.PROFILE_CURRENT_RESOURCE, alias='$schema')
  
      class-attribute
      instance-attribute
  
¶
    A profile URL
            schema: Optional[Union[Schema, str]] = None
  
      class-attribute
      instance-attribute
  
¶
    A schema property MAY be provided to specify Table Schema
            sources: List[Source] = []
  
      class-attribute
      instance-attribute
  
¶
    The raw sources for this data resource.
            title: Optional[str] = None
  
      class-attribute
      instance-attribute
  
¶
    Title or label for the resource.
            type: Optional[str] = None
  
      class-attribute
      instance-attribute
  
¶
    Type of the resource e.g. "table"
            compat(data)
  
      classmethod
  
¶
    Source code in dplib/models/resource/resource.py
              
            dereference()
¶
    Dereference the package It will dereference all the resource's dialects and schemas
Source code in dplib/models/resource/resource.py
              
            get_dialect()
¶
    Get the resolved dialect of the resource
Returns:
| Type | Description | 
|---|---|
                  Optional[Dialect]
             | 
            
               The resolved dialect of the resource  | 
          
Source code in dplib/models/resource/resource.py
              
            get_fullpath()
¶
    Get the full path of the resource
Returns:
| Type | Description | 
|---|---|
                  Optional[str]
             | 
            
               The full path of the resource  | 
          
            get_hash()
¶
    Get the hash instance of the resource
Returns:
| Type | Description | 
|---|---|
                  Optional[Hash]
             | 
            
               The hash instance of the resource  | 
          
            get_schema()
¶
    Get the resolved schema of the resource
Returns:
| Type | Description | 
|---|---|
                  Optional[Schema]
             | 
            
               The resolved schema of the resource  | 
          
Source code in dplib/models/resource/resource.py
              
            get_source()
¶
    Get the source of the resource
Returns:
| Type | Description | 
|---|---|
                  Optional[Union[str, IDict]]
             | 
            
               Data or full path  | 
          
            dplib.models.License
¶
    
              Bases: Model
Source code in dplib/models/license.py
                
              
            dplib.models.Source
¶
    
              Bases: Model
Source code in dplib/models/source.py
                
              
            dplib.models.Contributor
¶
    
              Bases: Model