Package: tin
HEAD:Release:TinTin is a thin and minimal wrapper aroundpython requestsintended as a generic REST API client library.APIs are definedasYAMLwherein API services, enpoints, methods and such that API specs can be updated easily without changing python code.  A bit like a poor man'sSwagger/OpenAPI.On the subject of Swagger/OpenAPIIf the REST API you need to interact with publishes an OpenAPI spec, you very
likely do not need Tin.  There are a variety of much more robustOpenAPI toolsthat will generate API
client code, among other functions.
Tin was made with services thatdon'tpublish OpenAPI data in mind. That being said, it'll still work fine with any REST API that speaks JSON.FeaturesSupports multiple environment definitions per APIBasic, header and parameter based authenticationCredentials from a YML or JSON file, or environment varsA minimal model system where lists of json dicts returned from a service
can be instantiated as custom objects with canned CRUD methods such
as.create()and.save()Simple field validation for models, for specifying required and/or read-only fields.Requests session supportGenerally any option that can be passed to requests.UsageWith an service, API and model files such asService definition---environments:production:host:yourhost.service.comscheme:httpsport:443credentials:~/path/to/credentials.ymlauth_type:basicssl:verify:trueapi_file:path/to/service-api.ymlmodel_file:path/to/service-models.ymlcommon:# Common settings apply to all environmentscontent_type:"application/json"basepath:"/api/v2"params:may:["links","filter_by","filter_value"]API Definition---things:response_data_key:"things"# if interesting data comes back under a toplevel key, return only what's under that keyobjects_data_key:"othings"# Retain the original structure of the response, but look under this key for objects to be cast to modelsmodel:thing# Optional: associated model from the models filemethods:create:method:POSTpath:/thingsobject_method:create# this method will be associated with model_instance.create()expect:201get:method:GETpath:/things/:idobject_method:read# this method will be associated with model_instance.refresh()list:method:GETpath:/thingsModels Definition---thing:id_attr:idread_only:# read-only-idmust:# When saving a newly created model instance, these attrs are required-name-emailmay:# Optional attrs that will be sent to the service API if set in the model instance-description-extra_stuffTin can be used like thisfromtin.apiimportTinApimyapi=TinApi(config_file='path/to/myapi_definition.yml',environment='production')things=myapi.things.list()# returns {'things': [<myapi.things.thing>, <myapi.things.thing>...]}things=myapi.things.list(nomodel=True)# returns {'things': [ {'id': 1, name: 'thingname', 'email': 'mail@example.com'} ... ]thing=myapi.things.get(1)thing=myapi.things.get(id=1)thing.name# "thingname"thing.name="newname"thing.save()thing.name# "newname"newthing=myapi.things.model({})newthing.save()# fails validation as name and email aren't setnewthing.name='new thing'newthing.email='mail@example.com'newthing.save()# succeedsnewthing.update({'name':'new name'})# updates instance and makes Update API callnewthing.delete()