Package: postcodeinfo
Python package providing an API client forhttps://github.com/ministryofjustice/postcodeinfowhich contains public sector information licensed under the Open Government License v2.0InstallationpipinstallpostcodeinfoUsageAuthenticationYou will need anauthentication token(auth token). If you’re using MOJ DS’s
Postcode Info server, you can get a token by emailingplatforms@digital.justice.gov.ukwith a brief summary of:who you arewhat project you’re going to be using it onroughly how many lookups you expect to do per dayIf you’re running your own server, seehttps://github.com/ministryofjustice/postcodeinfo#auth_tokensfor instructions
on how to create a token.Quick StartIn your code:>>>importpostcodeinfo>>># create a client>>>client=postcodeinfo.Client("YOUR-ACCESS-TOKEN")>>># lookup a postcode>>>postcode=client.lookup_postcode("SW1A 1AA")>>># postcode details>>>postcode.validTrue>>>postcode.latitude51.50100893654096>>>postcode.longitude-0.141587558526369>>>postcode.local_authority{'gss_code':'E09000033','name':'Westminster'}>>>postcode.country{"name":"England","gss_code":"E92000001"}>>>postcode.addresses[{"uprn":"10033544614","organisation_name":"BUCKINGHAM PALACE","department_name":"","po_box_number":"","building_name":"","sub_building_name":"","building_number":None,"thoroughfare_name":"","dependent_thoroughfare_name":"","dependent_locality":"","double_dependent_locality":"","post_town":"LONDON","postcode":"SW1A 1AA","postcode_type":"L","formatted_address":"Buckingham Palace\nLondon\nSW1A 1AA","point":{"type":"Point","coordinates":[-0.141587558526369,51.50100893654096]}}]ConfigurationApart from the auth token, there is only one other parameter the API client
needs -api_url.Explicitapi_urlYou can set the api_url explicitly by passing it to theClientconstructor# create a clientclient=postcodeinfo.Client("YOUR-API-TOKEN",api_url="https://some.dom.ain")or by setting it on an existing client, like thisclient=postcodeinfo.Client("YOUR-API-TOKEN")client.api_url="https://some.dom.ain"Implicitapi_urlIf you don’t pass anapi_urlto the constructor, it will attempt to infer
one from the environment. The client has a built-in mapping of environment names
to URLs.>>>postcodeinfo.Client.api_urls{'development':'http://localhost:8000','test':'http://localhost:8000','staging':'https://postcodeinfo-staging.dsd.io','production':'https://postcodeinfo.service.justice.gov.uk'}It will use the following rules to infer the URL:If you pass anenvparameter to the constructor (eg:client =postcodeinfo.Client("YOUR-API-TOKEN",env="staging")), it will
use that as a reference into theapi_urlsmapping.If you haveDJANGO_SETTINGS_MODULEset in your environment, it will try
to find the following settings in that module:POSTCODEINFO_API_URL
POSTCODEINFO_API_TOKEN
POSTCODEINFO_API_TIMEOUTOtherwise it will default todevelopmentSupportThis source code is provided as-is, with no incident response or support levels.
Please log all questions, issues, and feature requests in the Github issue
tracker for this repo, and we’ll take a look as soon as we can. If you’re
reporting a bug, then it really helps if you can provide the smallest possible
bit of code that reproduces the issue. A failing test is even better!ContributingCheck out the latest master to make sure the feature hasn’t been implemented
or the bug hasn’t been fixedCheck the issue tracker to make sure someone hasn’t already requested
and/or contributed the featureFork the projectStart a feature/bugfix branchCommit and push until you are happy with your contributionMake sure your changes are covered by unit tests, so that we don’t break it
unintentionally in the future.Please don’t mess with setup.py, version or history.CopyrightCopyright © 2015 HM Government (Ministry of Justice Digital Services). See
LICENSE for further details.