README.rst 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. =========
  2. webfinger
  3. =========
  4. A simple Python client implementation of `WebFinger RFC 7033 <http://tools.ietf.org/html/rfc7033>`_.
  5. WebFinger is a discovery protocol that allows you to find information about people or things in a standardized way. See the `spec <http://tools.ietf.org/html/rfc7033>`_ or `webfinger.net <http://webfinger.net>`_ for more information.
  6. ::
  7. >>> from webfinger import finger
  8. >>> wf = finger('acct:eric@konklone.com')
  9. >>> wf.subject
  10. acct:eric@konklone.com
  11. >>> wf.avatar
  12. https://secure.gravatar.com/avatar/ac3399caecce27cb19d381f61124539e.jpg?s=400
  13. >>> wf.profile
  14. https://konklone.com
  15. >>> wf.properties.get('http://schema.org/name')
  16. Eric Mill
  17. Installation
  18. ============
  19. Available on `PyPI as webfinger <https://pypi.python.org/pypi/webfinger>`_.
  20. pip install webfinger
  21. finger
  22. ======
  23. finger(resource, rel=None)
  24. *finger* is a convenience method for instantiating a WebFingerClient object and making the request. The *resource* parameter is a URI of the resource about which you are querying. The optional *rel* parameter can be either a string or a list of strings that will limit the response to the specific relations. WebFinger servers are **not** required to obey the *rel* parameter, so you should handle the response accordingly.
  25. WebFingerClient supports additional options, so check that out if *finger* does not meet your needs.
  26. WebFinger Client
  27. ================
  28. WebFingerClient(timeout=None, official=False)
  29. Instantiates a client object. The optional *timeout* parameter specifies the HTTP request timeout. The optional *official* parameter is a boolean that determines if the client will use `unofficial endpoints`_.
  30. finger(resource, host=None, rel=None, raw=False)
  31. The client *finger* method prepares and executes the WebFinger request. *resource* and *rel* are the same as the parameters on the standalone *finger* method. *host* should only be specified if you want to connect to a host other than the host in the resource parameter. Otherwise, this method extracts the host from the *resource* parameter. *raw* is a boolean that determines if the method returns a WebFingerResponse object or the raw JRD response as a dict.
  32. If the *host* parameter is passed to this method, unofficial endpoints are ignored. You're asking for a specific host so who am I to disagree?
  33. WebFinger Response
  34. ==================
  35. The WebFinger response object provides handy properties for easy access and the raw JRD response. Read the `spec for specifics of the JRD response <http://tools.ietf.org/html/rfc7033#section-4.4>`_.
  36. Properties
  37. ----------
  38. subject
  39. The URI of the thing that the response JRD describes.
  40. aliases
  41. A list of additional URIs that identify the subject.
  42. properties
  43. A dict of URIs and values that provides information about the subject.
  44. links
  45. A list of dicts that define external resources for the subject.
  46. jrd
  47. A dict of the raw JRD response.
  48. Methods
  49. -------
  50. rel(relation, attr='href')
  51. A convenience method that provides basic access to links. The *relation* parameter is a URI for the desired link. The *attr* parameter is the key of the returned value of the link that matches *relation*. Returns a string if *relation* and *attr* exist, otherwise *None*.
  52. ::
  53. >>> wf.rel('http://webfinger.net/rel/avatar')
  54. https://secure.gravatar.com/avatar/ac3399caecce27cb19d381f61124539e.jpg?s=400
  55. The response JRD may have multiple entries with the same relation URI. The *rel* method will select the first one, since order is meant to imply priority. If you need to see all of the values, you'll have to iterate over the *links* property and pull them out yourself.
  56. ::
  57. >>> rel = 'http://webfinger.net/rel/avatar'
  58. >>> [l.get('href') for l in rel.links if l.get('rel') == rel]
  59. If *attr* is None, the full dict for the link will be returned.
  60. Relation Properties
  61. -------------------
  62. The following common link relation types are supported as properties of the response object:
  63. * activity_streams: http://activitystrea.ms/spec/1.0
  64. * avatar: http://webfinger.net/rel/avatar
  65. * hcard: http://microformats.org/profile/hcard
  66. * open_id: http://specs.openid.net/auth/2.0/provider
  67. * opensocial: http://ns.opensocial.org/2008/opensocial/activitystreams
  68. * portable_contacts: http://portablecontacts.net/spec/1.0
  69. * profile: http://webfinger.net/rel/profile-page
  70. * webfist: http://webfist.org/spec/rel
  71. * xfn: http://gmpg.org/xfn/11
  72. Example::
  73. >>> wf.avatar
  74. https://secure.gravatar.com/avatar/ac3399caecce27cb19d381f61124539e.jpg?s=400
  75. .. _unofficial endpoints:
  76. Unofficial Endpoints
  77. ====================
  78. While Facebook and Twitter do not officially support WebFinger, the `webfinger-unofficial project <https://github.com/snarfed/webfinger-unofficial>`_ provides a proxy for basic subject information. By default, python-webfinger will attempt to use the unofficial endpoints for facebook.com and twitter.com resource domains. This behavior can be disabled by passing *True* to the *official* parameter::
  79. >>> wf = finger('acct:konklone@twitter.com', official=True)
  80. Dependencies
  81. ============
  82. * `requests <https://pypi.python.org/pypi/requests>`_
  83. License
  84. =======
  85. python-webfinger is distributed under the `BSD license <http://creativecommons.org/licenses/BSD/>`_.
  86. See LICENSE for the full terms.