Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Immutable struct with sane defaults

Project Description

Immutable struct built on top of collections.namedtuple with sane defaults


  • Immutable, dictionary-like data structure (Note: istruct is not an immutable version of the existing struct in Python)
  • Minimal
  • Support required and optional fields (with default values)
  • Strictly disallow positional arguments


pip install istruct

Quick Start

First, create an istruct object called person where first_name and last_name are required whereas middle_name, dob and email are optional (with default values specified).

>>> from istruct import istruct
>>> person = istruct("first_name", "last_name", middle_name="", dob="2000-01-01", email=None)

Then, create an instance of person with first_name, last_name and middle_name.

>>> p = person(first_name="Jim", last_name="Raynor", middle_name="Eugene")
>>> p
istruct(first_name='Jim', last_name='Raynor', email=None, dob='2000-01-01', middle_name='Eugene')

You can retrieve field values like you would normally do.

>>> p.first_name
>>> p.dob

p is immutable, meaning that it cannot be modified after created. Thus, set/delete operations like below would fail, raising an AttributeError.

>>> p.first_name = "James"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: can't set attribute
>>> del
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: can't delete attribute

istruct only accepts named/keyword arguments. It strictly disallows positional arguments by design.

>>> p = person("Jim", "Raynor")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/microamp/src/microamp/istruct/istruct/", line 52, in _istruct
    "(%d found)" % (len(positional),))
TypeError: No positional arguments are allowed in istruct (2 found)

istruct would raise a TypeError when one or more required fields are omitted.

>>> p = person(last_name="Raynor")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/microamp/src/microamp/istruct/istruct/", line 56, in _istruct
    return nt(**merge_dicts(kwargs, attrs))
TypeError: __new__() missing 1 required positional argument: 'first_name'

Versions Tested

  • Python 2.7
  • Python 3.2
  • Python 3.3
  • Python 3.4
  • Python 3.5
  • Python 3.6
  • PyPy
  • PyPy3


  • Find ways to annotate types



Release History

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
istruct-0.1.6.tar.gz (2.8 kB) Copy SHA256 Checksum SHA256 Source Apr 22, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting