Skip to main content

Context data structure

Project description

vcontext
========

Context is dictionary datastructure with custom access to items.
You can access your data by dot access.
Context does not wrap data in itself, rather just access them. Context has `data` attribute where data is stored.

Let show an example:

context = Context({
'status': 200,
'message': 'OK',
'result': [
{
'user': {
'username': 'phonkee',
'name': 'Peter Vrba'
}
}
]
})

You can access data like this:

assert context['result.0.user.username'] == 'phonkee'
assert context['status'] == 200

Key can have multiple parts. Rules are following:
* string - access to dictionary key or object attribute
* integer - access to list item
* first part must be string (since Context is a dictionary

Context can also be used to build complicated datastructures with ease.
Lets build a structure from previous example:

context = Context()
context['status'] = 200
context['message'] = 'OK'
context['result.0.user.username'] = 'phonkee'
context['result.0.user.name'] = 'Peter Vrba'

assert context.data == {
'status': 200,
'message': 'OK',
'result': [
{
'user': {
'username': 'phonkee',
'name': 'Peter Vrba'
}
}
]
}

Context has also support for delete so let's assume that we use context from previous example:

del context['result.0']
assert len(context['result']) == 0

Isn't that neat small helper for your next projects?

Contribute
----------

Contributions are welcome, there are still a lot of parts to be enhanced.

Author
------

Peter Vrba (phonkee)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vcontext-0.3.tar.gz (3.8 kB view details)

Uploaded Source

File details

Details for the file vcontext-0.3.tar.gz.

File metadata

  • Download URL: vcontext-0.3.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for vcontext-0.3.tar.gz
Algorithm Hash digest
SHA256 0c61a46a56026fdf814a9469639b0574629e15cee7435d7f469b8c8e9c39f464
MD5 5ba293fabb443701168246db0c1107a0
BLAKE2b-256 5a68a245bfb19a4d9702693c917e4c6290d0c0783e0841fbf2eb5dc7c4b8059c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page