Skip to content

Commit ec0e00b

Browse files
authored
Merge pull request #471 from OpenDataServices/final_bods_0_4
Allow passing schema as a Python object
2 parents e29ab09 + fba9979 commit ec0e00b

18 files changed

+2217
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1212
- Put back some translations that were removed
1313
- Minor python tidyups
1414
- Avoid deprecation warning from the ijson package. https://github.com/OpenDataServices/flatten-tool/pull/458
15+
- Allow passing of schema as Python object, and update docs
1516

1617
### Removed
1718

docs/getting-started.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,27 @@ will print general help information.
3838
3939
will print help information specific to that sub-command.
4040

41+
Library
42+
-------
43+
44+
The package can also be used as a Python library, e.g. to flatten
45+
data:
46+
47+
.. code-block:: python
48+
49+
flattentool.flatten(input_filename, ...)
50+
51+
or unflatten data:
52+
53+
.. code-block:: python
54+
55+
flattentool.unflatten(input_filename, ...)
56+
57+
In addition to the functionality available from the command-line,
58+
Python calls to the library functions also accept a Python object
59+
as a schema rather than a filename. This allows schema objects to
60+
be loaded/constructed by the calling application.
61+
4162
Python Version Support
4263
----------------------
4364

flattentool/schema.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ def __init__(
152152
_("Only one of schema_filename or root_schema_dict should be supplied")
153153
)
154154
if schema_filename:
155-
if schema_filename.startswith("http"):
155+
if isinstance(schema_filename, dict):
156+
self.root_schema_dict = schema_filename
157+
elif schema_filename.startswith("http"):
156158
import requests
157159

158160
r = requests.get(schema_filename)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
addresses/0/type,addresses/0/address,addresses/0/postCode,addresses/0/country,statementID
2+
service,"Aston House, Cornwall Avenue, London",N3 1LF,GB,019a93f1-e470-42e9-957b-03559861b2e2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
annotations/0/statementPointerTarget,annotations/0/creationDate,annotations/0/createdBy/name,annotations/0/createdBy/uri,annotations/0/motivation,annotations/0/description,annotations/0/transformedContent,annotations/0/url
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
identifiers/0/id,identifiers/0/scheme,identifiers/0/schemeName,identifiers/0/uri,statementID
2+
07444723,GB-COH,,,1dc0e987-5c57-4a1c-b3ad-61353b66a9b7
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
interests/0/type,interests/0/directOrIndirect,interests/0/beneficialOwnershipOrControl,interests/0/details,interests/0/share/exact,interests/0/share/maximum,interests/0/share/minimum,interests/0/share/exclusiveMinimum,interests/0/share/exclusiveMaximum,interests/0/startDate,interests/0/endDate,statementID
2+
shareholding,direct,True,,100,100,100,,,2016-04-06,,fbfd0547-d0c6-4a00-b559-5c5e91c34f5c
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
statementID,statementType,statementDate,isComponent,entityType,unspecifiedEntityDetails/reason,unspecifiedEntityDetails/description,name,alternateNames,jurisdiction/name,jurisdiction/code,foundingDate,dissolutionDate,uri,replacesStatements,publicationDetails/publicationDate,publicationDetails/bodsVersion,publicationDetails/license,publicationDetails/publisher/name,publicationDetails/publisher/url,source/type,source/description,source/url,source/retrievedAt,publicListing/hasPublicListing,publicListing/companyFilingsURLs,entitySubtype/generalCategory,entitySubtype/localTerm,formedByStatute/name,formedByStatute/date,personType,unspecifiedPersonDetails/reason,unspecifiedPersonDetails/description,placeOfBirth/type,placeOfBirth/address,placeOfBirth/postCode,placeOfBirth/country,birthDate,deathDate,placeOfResidence/type,placeOfResidence/address,placeOfResidence/postCode,placeOfResidence/country,politicalExposure/status,componentStatementIDs,subject/describedByEntityStatement,interestedParty/describedByEntityStatement,interestedParty/describedByPersonStatement,interestedParty/unspecified/reason,interestedParty/unspecified/description,publicListing/securitiesListings
2+
1dc0e987-5c57-4a1c-b3ad-61353b66a9b7,entityStatement,2017-11-18,False,registeredEntity,,,CHRINON LTD,,,,2010-11-18,,,,2018-02-13,0.3,,CHRINON LTD,,,,,,True,http://example.com/,,,,,,,,,,,,,,,,,,,,,,,,,
3+
019a93f1-e470-42e9-957b-03559861b2e2,personStatement,2017-11-18,False,,,,,,,,,,,,2018-02-13,0.3,,CHRINON LTD,,,,,,,,,,,,knownPerson,,,,,,,1964-04,,,,,,,,,,,,,
4+
fbfd0547-d0c6-4a00-b559-5c5e91c34f5c,ownershipOrControlStatement,2017-11-18,False,,,,,,,,,,,,2018-02-13,0.3,,CHRINON LTD,,,,,,,,,,,,,,,,,,,,,,,,,,,1dc0e987-5c57-4a1c-b3ad-61353b66a9b7,,019a93f1-e470-42e9-957b-03559861b2e2,,,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
names/0/type,names/0/fullName,names/0/familyName,names/0/givenName,names/0/patronymicName,statementID
2+
individual,Christopher Taggart,Taggart,Christopher,,019a93f1-e470-42e9-957b-03559861b2e2
3+
alternative,Chris Taggart,,,,019a93f1-e470-42e9-957b-03559861b2e2
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
nationalities/0/name,nationalities/0/code,statementID
2+
United Kingdom of Great Britain and Northern Ireland (the),GB,019a93f1-e470-42e9-957b-03559861b2e2

0 commit comments

Comments
 (0)