attrimotif
An attributed directed bipartite motif inference workflow in Python.
attrimotif chains the four steps an empirical study of an attributed directed
bipartite network (buyer → brand, tourist → spot, user → movie) usually has to
assemble from scattered tools:
- Census — directed bipartite motif counts (size-3 fan-out / fan-in; size-4 fans and the 2×2 overlap / 4-cycle).
- Typed — stratify each motif class by a categorical node type, and apply the operator Φ to read the distribution of a numeric edge attribute over motif instances (exposing tails a count collapses).
- Nulls — a degree-preserving bipartite null with a null-identifiability diagnostic that flags statistics which are exact functions of the degree sequence (so the null cannot identify them).
- Compare — panel-level Portrait Divergence with a random-partition permutation test.
It is not a general directed-motif or colored-graph-isomorphism engine: the
scope is deliberately attributed bipartite motifs on fixed templates, which is
what the motivating empirical problems need and what keeps the package small,
permissively licensed (MIT), and dependency-light (numpy, scipy,
networkx; netrd optional).
Install
pip install attrimotif # from PyPI
pip install -e .[dev] # from a checkout, with test/plot extras
Quickstart
import attrimotif as am
d = am.datasets.synthetic_panel(seed=0)
g = d["graph"]
am.census(g) # {'fan-out':..,'fan-in':..,'overlap':..,..}
am.stratified_census(g) # counts by node category
am.phi_distributions(g) # operator Φ: per-class attribute distributions
am.null_test(g, "overlap") # identifiable → z, permutation p
am.null_test(g, "fan-out") # flagged: degree-determined, not identifiable
am.panel_permutation_test(g, d["agent_panel"]) # cross-panel Portrait Divergence
Note. A repeated arc collapses for all topological counts;
edge_attrholds one value per arc, so aggregate repeated observations (e.g. several purchases of the same brand) into a single weight before constructing the graph.
Portrait Divergence backend
The bundled implementation is dependency-light. If netrd
is installed, am.portrait_divergence(g1, g2, backend="netrd") delegates to its
reference implementation for computing Portrait Divergence. The bundled and netrd
backends agree on identity (PD(G, G) = 0) and on ordering, but may differ slightly
in how the k-axis is binned across graphs of different sizes.
Relation to existing tools
attrimotif does not claim a new algorithm. Directed motif census
(NetworkX, graph-tool, gtrieScanner), degree-preserving randomization (NetworkX,
graph-tool, xswap), and Portrait Divergence (Bagrow & Bollt 2019; netrd) all
exist separately. attrimotif's contribution is the integration of an
attributed bipartite motif census, the identifiability diagnostic, operator
Φ, and panel-level Portrait Divergence into one reproducible, installable
workflow. See CITATION.cff and the paper for the full comparison.
Data statement
The package ships only synthetic generators (attrimotif.datasets) and
reads user-supplied or public-download data. No proprietary records are included
or required; .gitignore blocks confidential source files from the repository.
Tests
pip install -e .[dev]
pytest
License
MIT — see LICENSE.
Metadata
Release files for attrimotif 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| attrimotif-1.1.1.tar.gz | 58.9 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| attrimotif-1.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 83.9 kB
Release files / attrimotif-1.1.1.tar.gz
| Download URL | attrimotif-1.1.1.tar.gz |
|---|---|
| Size | 58.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a9316b9d13bdcd9ade5d4aba7fbf6518f3d603e03341373fdf6de78d5eaa02a0
|
|
BLAKE2b-256 checksum How to use checksums |
716c5e4fd5b8f8c26554720475966bb83f2248ef86a65424bb44545ad292ed16
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.
Transparency logRelease files / attrimotif-1.1.1-py3-none-any.whl
| Download URL | attrimotif-1.1.1-py3-none-any.whl |
|---|---|
| Size | 24.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4972e0cb501d0a4beb57d23364a9134bb9f585e269cacfc76fbf16c349b2a2a8
|
|
BLAKE2b-256 checksum How to use checksums |
fbfba4f864bcbf9532ca361eca6fdc1aa2c9acec891ac8b8610fe093a1522cc5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.
Transparency logSecurity for attrimotif 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for attrimotif-1.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.